mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 增加 FreeSqlBuilder UseSeedData 设定 CodeFirst 种子数据;
This commit is contained in:
@ -25,8 +25,7 @@ namespace FreeSql
|
||||
{
|
||||
var tkeyType = typeof(TKey)?.NullableTypeOrThis();
|
||||
if (tkeyType == typeof(int) || tkeyType == typeof(long))
|
||||
Orm.CodeFirst.ConfigEntity(typeof(TEntity),
|
||||
t => t.Property("Id").IsIdentity(true));
|
||||
BaseEntity.ConfigEntity(typeof(TEntity), t => t.Property("Id").IsIdentity(true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -21,8 +21,7 @@ namespace FreeSql
|
||||
{
|
||||
var tkeyType = typeof(TKey)?.NullableTypeOrThis();
|
||||
if (tkeyType == typeof(int) || tkeyType == typeof(long))
|
||||
Orm.CodeFirst.ConfigEntity(typeof(TEntity),
|
||||
t => t.Property("Id").IsIdentity(true));
|
||||
BaseEntity.ConfigEntity(typeof(TEntity), t => t.Property("Id").IsIdentity(true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -4,6 +4,7 @@ using FreeSql.DataAnnotations;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@ -18,7 +19,7 @@ namespace FreeSql
|
||||
[Table(DisableSyncStructure = true)]
|
||||
public abstract class BaseEntity
|
||||
{
|
||||
static IFreeSql _ormPriv;
|
||||
internal static IFreeSql _ormPriv;
|
||||
/// <summary>
|
||||
/// 全局 IFreeSql orm 对象
|
||||
/// </summary>
|
||||
@ -42,6 +43,32 @@ namespace FreeSql
|
||||
{
|
||||
_ormPriv = fsql;
|
||||
_ormPriv.Aop.CurdBefore += (s, e) => Trace.WriteLine($"\r\n线程{Thread.CurrentThread.ManagedThreadId}: {e.Sql}\r\n");
|
||||
if (_configEntityQueues.Any())
|
||||
{
|
||||
lock (_configEntityLock)
|
||||
{
|
||||
while (_configEntityQueues.TryDequeue(out var cei))
|
||||
_ormPriv.CodeFirst.ConfigEntity(cei.EntityType, cei.Fluent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigEntityInfo
|
||||
{
|
||||
public Type EntityType;
|
||||
public Action<TableFluent> Fluent;
|
||||
}
|
||||
static ConcurrentQueue<ConfigEntityInfo> _configEntityQueues = new ConcurrentQueue<ConfigEntityInfo>();
|
||||
static object _configEntityLock = new object();
|
||||
internal static void ConfigEntity(Type entityType, Action<TableFluent> fluent)
|
||||
{
|
||||
lock (_configEntityLock)
|
||||
{
|
||||
if (_ormPriv == null)
|
||||
_configEntityQueues.Enqueue(new ConfigEntityInfo { EntityType = entityType, Fluent = fluent });
|
||||
else
|
||||
_ormPriv.CodeFirst.ConfigEntity(entityType, fluent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user