|
- 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<T> : DbContext where T : class, new()
- {
-
- private volatile static Sqlite<T> _Instance;
- public static Sqlite<T> GetInstance => _Instance ?? (_Instance = new Sqlite<T>());
- private Sqlite() { }
-
- public DbSet<T> 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();
- }
-
- }
- }
|