|
- using HKLib.DB.Model;
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using XExten.Advance.StaticFramework;
-
- namespace HKLib.DB
- {
- public class DbContext
- {
- public static SqlSugarScope Context = new SqlSugarScope(new ConnectionConfig()
- {
- ConnectionString = Route,
- DbType = DbType.Sqlite,//数据库类型
- IsAutoCloseConnection = true //不设成true要手动close
- }, db =>
- {
- db.Aop.OnLogExecuting = (sql, pars) =>
- {
-
- };
- });
-
- public static string Route
- {
- get
- {
- var dir = SyncStatic.CreateDir(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Database"));
- return $"DataSource={SyncStatic.CreateFile(Path.Combine(dir, "Data.db3"))}";
- }
- }
- public static void InitTable()
- {
- var Tables = Assembly.GetAssembly(typeof(DbContext))
- .GetTypes().Where(t => t.BaseType == typeof(BaseEntity)).ToArray();
- Context.CodeFirst.InitTables(Tables);
- }
- }
- }
|