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.

DbContext.cs 1000 B

2 jaren geleden
1234567891011121314151617181920212223242526272829303132
  1. using SqlSugar;
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using XExten.Advance.StaticFramework;
  7. namespace HKLib.SQLHelper
  8. {
  9. public class DbContext
  10. {
  11. public static SqlSugarScope Context = new SqlSugarScope(new ConnectionConfig()
  12. {
  13. ConnectionString = $"DataSource={SyncStatic.CreateFile(Path.Combine(SyncStatic.CreateDir(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DATA")), "data.db3"))}",//连接符字串
  14. DbType = DbType.Sqlite,//数据库类型
  15. IsAutoCloseConnection = true //不设成true要手动close
  16. }, db =>
  17. {
  18. db.Aop.OnLogExecuting = (sql, pars) =>
  19. {
  20. };
  21. });
  22. public static void InitTable()
  23. {
  24. var Tables = Assembly.GetAssembly(typeof(DbContext))
  25. .GetTypes().Where(t => t.BaseType == typeof(BaseEntity)).ToArray();
  26. Context.CodeFirst.InitTables(Tables);
  27. }
  28. }
  29. }