Add CodeFirst helper
This commit is contained in:
parent
5f9f86663e
commit
cf7ebb3cbc
|
@ -1,25 +1,32 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Serilog;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace LFlow.Base.Utils;
|
namespace LFlow.Base.Utils;
|
||||||
|
|
||||||
public static class CodeFirst
|
public static class CodeFirst
|
||||||
{
|
{
|
||||||
private static List<Type> _tableTypes = new List<Type>();
|
// 线程安全的类型列表
|
||||||
|
private static readonly ConcurrentBag<Type> _types = new();
|
||||||
internal static void RegisterTable(Type type)
|
public static void AddType(Type type)
|
||||||
{
|
{
|
||||||
if (_tableTypes.Contains(type))
|
_types.Add(type);
|
||||||
|
}
|
||||||
|
internal static void InitTable()
|
||||||
|
{
|
||||||
|
var logger = App.GetService<Serilog.ILogger>()!;
|
||||||
|
var db = App.GetService<ISqlSugarClient>()!;
|
||||||
|
foreach (var type in _types)
|
||||||
{
|
{
|
||||||
return;
|
db.CodeFirst.InitTables(type);
|
||||||
}
|
logger.Information($"Init table {type.Name} success");
|
||||||
else
|
|
||||||
{
|
|
||||||
_tableTypes.Add(type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal static void DBSeed()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
internal static void InitDBSeed()
|
||||||
|
{
|
||||||
|
//TODO: Seed data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue