mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
Code cleanup.
This commit is contained in:
parent
5dd8210653
commit
73d2bfc680
@ -8,7 +8,9 @@ using System.Linq;
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable CheckNamespace
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
// ReSharper disable InconsistentlySynchronizedField
|
||||||
namespace FreeSql
|
namespace FreeSql
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -19,13 +21,16 @@ namespace FreeSql
|
|||||||
{
|
{
|
||||||
internal static IFreeSql _ormPriv;
|
internal static IFreeSql _ormPriv;
|
||||||
|
|
||||||
|
private const string ErrorMessageTemplate = @"使用前请初始化:
|
||||||
|
BaseEntity.Initialization(new FreeSqlBuilder()
|
||||||
|
.UseAutoSyncStructure(true)
|
||||||
|
.UseConnectionString(DataType.Sqlite, ""data source=test.db;max pool size=5"")
|
||||||
|
.Build());";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 全局 IFreeSql orm 对象
|
/// 全局 IFreeSql orm 对象
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static IFreeSql Orm => _ormPriv ?? throw new Exception(@"使用前请初始化 BaseEntity.Initialization(new FreeSqlBuilder()
|
public static IFreeSql Orm => _ormPriv ?? throw new Exception(ErrorMessageTemplate);
|
||||||
.UseAutoSyncStructure(true)
|
|
||||||
.UseConnectionString(DataType.Sqlite, ""data source=test.db;max pool size=5"")
|
|
||||||
.Build());");
|
|
||||||
|
|
||||||
internal static Func<IUnitOfWork> _resolveUow;
|
internal static Func<IUnitOfWork> _resolveUow;
|
||||||
|
|
||||||
@ -63,8 +68,8 @@ namespace FreeSql
|
|||||||
public Action<TableFluent> Fluent;
|
public Action<TableFluent> Fluent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ConcurrentQueue<ConfigEntityInfo> _configEntityQueues = new();
|
static readonly ConcurrentQueue<ConfigEntityInfo> _configEntityQueues = new();
|
||||||
static object _configEntityLock = new();
|
static readonly object _configEntityLock = new();
|
||||||
|
|
||||||
internal static void ConfigEntity(Type entityType, Action<TableFluent> fluent)
|
internal static void ConfigEntity(Type entityType, Action<TableFluent> fluent)
|
||||||
{
|
{
|
||||||
@ -131,26 +136,29 @@ namespace FreeSql
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var isFirst = true;
|
var isFirst = true;
|
||||||
|
IBaseRepository<TEntity> baseRepo = null;
|
||||||
IBaseRepository<TEntity> berepo = null;
|
|
||||||
|
|
||||||
foreach (var item in ie)
|
foreach (var item in ie)
|
||||||
{
|
{
|
||||||
if (item is null) return;
|
if (item is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isFirst)
|
if (isFirst)
|
||||||
{
|
{
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
var itemType = item.GetType();
|
var itemType = item.GetType();
|
||||||
if (itemType == typeof(object)) return;
|
if (itemType == typeof(object)) return;
|
||||||
if (itemType.FullName.Contains("FreeSqlLazyEntity__")) itemType = itemType.BaseType;
|
if (itemType.FullName!.Contains("FreeSqlLazyEntity__")) itemType = itemType.BaseType;
|
||||||
if (Orm.CodeFirst.GetTableByEntity(itemType)?.Primarys.Any() != true) return;
|
if (Orm.CodeFirst.GetTableByEntity(itemType)?.Primarys.Any() != true) return;
|
||||||
if (item is BaseEntity<TEntity> == false) return;
|
if (item is not BaseEntity<TEntity>) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item is BaseEntity<TEntity> entity)
|
if (item is BaseEntity<TEntity> entity)
|
||||||
{
|
{
|
||||||
berepo ??= Orm.GetRepository<TEntity>();
|
baseRepo ??= Orm.GetRepository<TEntity>();
|
||||||
entity.Repository = berepo;
|
entity.Repository = baseRepo;
|
||||||
entity.Attach();
|
entity.Attach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user