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 BPASmartClient.Helper { 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 { int Year = DateTime.Now.Year; int Month = DateTime.Now.Month; Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"AccessFile\\DB\\{Year}-{Month}")); return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DB\\{Year}-{Month}\\{typeof(T).Name}.db"; } } public bool DataBaseExist() { return Database.EnsureCreated(); } public void Save() { Database.EnsureCreated(); var a = SaveChanges(); } public List GetData() { Database.EnsureCreated(); return Base.ToList(); } } }