You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
1017 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Microsoft.EntityFrameworkCore;
  8. using Microsoft.EntityFrameworkCore.Sqlite;
  9. namespace HBLConsole.Service
  10. {
  11. public class Sqlite<T> : DbContext where T : class, new()
  12. {
  13. private volatile static Sqlite<T> _Instance;
  14. public static Sqlite<T> GetInstance => _Instance ?? (_Instance = new Sqlite<T>());
  15. private Sqlite() { }
  16. public DbSet<T> Base { get; set; }
  17. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  18. {
  19. optionsBuilder.UseSqlite($"FileName={path}");
  20. }
  21. static string path
  22. {
  23. get
  24. {
  25. Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\DB"));
  26. return $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\DB\\{typeof(T).Name}.db";
  27. }
  28. }
  29. }
  30. }