33 lines
746 B
C#
33 lines
746 B
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Net;
|
|
using Serilog;
|
|
using SqlSugar;
|
|
|
|
namespace LFlow.Base.Utils;
|
|
|
|
public static class CodeFirst
|
|
{
|
|
// 线程安全的类型列表
|
|
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 InitDBSeed()
|
|
{
|
|
//TODO: Seed data
|
|
}
|
|
}
|