|
- 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) =>
- {
-
- };
- });
-
- static string Route()
- {
- var dir = SyncStatic.CreateDir(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Database"));
- var r = SyncStatic.CreateFile(Path.Combine(dir, "data.db3"));
- return r;
- }
- public static void InitTable()
- {
- var Tables = Assembly.GetAssembly(typeof(DbContext))
- .GetTypes().Where(t => t.BaseType == typeof(BaseEntity)).ToArray();
- Context.CodeFirst.InitTables(Tables);
- }
- }
- }
|