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