using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Sqlite; namespace HBLConsole.Service { public class Sqlite : DbContext where T : class, new() { private volatile static Sqlite _Instance; public static Sqlite GetInstance => _Instance ?? (_Instance = new Sqlite()); private Sqlite() { } public DbSet Base { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlite($"FileName={path}"); } //static string path //{ // get // { // Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\DB")); // return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DB\\{typeof(T).Name}.db"; // } //} static string path { get { Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{LocaPath.GetInstance.FilePath}\\DB")); return $"{AppDomain.CurrentDomain.BaseDirectory}{LocaPath.GetInstance.FilePath}\\DB\\{typeof(T).Name}.db"; } } public void Save() { Database.EnsureCreated(); SaveChanges(); } public object GetData() { Database.EnsureCreated(); return Base.ToList(); } } }