|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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<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";
- }
- }
-
-
- public void Save()
- {
- Database.EnsureCreated();
- var a = SaveChanges();
- }
-
- public List<T> GetData()
- {
- Database.EnsureCreated();
- return Base.ToList();
- }
-
- }
- }
|