Add CodeFirst helper

This commit is contained in:
lihanbo 2024-10-16 11:25:57 +08:00
parent 5f9f86663e
commit cf7ebb3cbc
1 changed files with 18 additions and 11 deletions

View File

@ -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();
public static void AddType(Type type)
{
_types.Add(type);
}
internal static void InitTable()
{
var logger = App.GetService<Serilog.ILogger>()!;
var db = App.GetService<ISqlSugarClient>()!;
foreach (var type in _types)
{
db.CodeFirst.InitTables(type);
logger.Information($"Init table {type.Name} success");
}
}
internal static void RegisterTable(Type type) internal static void InitDBSeed()
{ {
if (_tableTypes.Contains(type)) //TODO: Seed data
{
return;
}
else
{
_tableTypes.Add(type);
}
}
internal static void DBSeed()
{
} }
} }