内部微调

This commit is contained in:
28810 2019-08-06 13:37:12 +08:00
parent d22bed3494
commit 71a0552871
2 changed files with 8 additions and 8 deletions

View File

@ -45,12 +45,12 @@ namespace FreeSql.Internal.CommonProvider
public abstract string GetComparisonDDLStatements(params Type[] entityTypes); public abstract string GetComparisonDDLStatements(params Type[] entityTypes);
static object syncStructureLock = new object(); static object syncStructureLock = new object();
internal ConcurrentDictionary<string, bool> dicSyced = new ConcurrentDictionary<string, bool>(); internal ConcurrentDictionary<Type, bool> dicSyced = new ConcurrentDictionary<Type, bool>();
public bool SyncStructure<TEntity>() => this.SyncStructure(typeof(TEntity)); public bool SyncStructure<TEntity>() => this.SyncStructure(typeof(TEntity));
public bool SyncStructure(params Type[] entityTypes) public bool SyncStructure(params Type[] entityTypes)
{ {
if (entityTypes == null) return false; if (entityTypes == null) return false;
var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a.FullName) == false && GetTableByEntity(a)?.DisableSyncStructure == false).ToArray(); var syncTypes = entityTypes.Where(a => dicSyced.ContainsKey(a) == false && GetTableByEntity(a)?.DisableSyncStructure == false).ToArray();
if (syncTypes.Any() == false) return false; if (syncTypes.Any() == false) return false;
var before = new Aop.SyncStructureBeforeEventArgs(entityTypes); var before = new Aop.SyncStructureBeforeEventArgs(entityTypes);
_orm.Aop.SyncStructureBefore?.Invoke(this, before); _orm.Aop.SyncStructureBefore?.Invoke(this, before);
@ -63,11 +63,11 @@ namespace FreeSql.Internal.CommonProvider
ddl = this.GetComparisonDDLStatements(syncTypes); ddl = this.GetComparisonDDLStatements(syncTypes);
if (string.IsNullOrEmpty(ddl)) if (string.IsNullOrEmpty(ddl))
{ {
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true); foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType, true);
return true; return true;
} }
var affrows = _orm.Ado.ExecuteNonQuery(CommandType.Text, ddl); var affrows = _orm.Ado.ExecuteNonQuery(CommandType.Text, ddl);
foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType.FullName, true); foreach (var syncType in syncTypes) dicSyced.TryAdd(syncType, true);
return true; return true;
} }
} }

View File

@ -213,7 +213,7 @@ namespace FreeSql.Internal.CommonProvider
if (typeof(TReturn) == typeof(T1)) return this as ISelect<TReturn>; if (typeof(TReturn) == typeof(T1)) return this as ISelect<TReturn>;
_tables[0].Parameter = select.Parameters[0]; _tables[0].Parameter = select.Parameters[0];
_selectExpression = select.Body; _selectExpression = select.Body;
(_orm.CodeFirst as CodeFirstProvider).dicSyced.TryAdd(typeof(TReturn).FullName, true); (_orm.CodeFirst as CodeFirstProvider).dicSyced.TryAdd(typeof(TReturn), true);
var ret = _orm.Select<TReturn>(); var ret = _orm.Select<TReturn>();
Select0Provider<ISelect<T1>, T1>.CopyData(this, ret, null); Select0Provider<ISelect<T1>, T1>.CopyData(this, ret, null);
return ret; return ret;
@ -228,7 +228,7 @@ namespace FreeSql.Internal.CommonProvider
), SelectTableInfoType.InnerJoin); ), SelectTableInfoType.InnerJoin);
if (typeof(TResult) == typeof(T1)) return this as ISelect<TResult>; if (typeof(TResult) == typeof(T1)) return this as ISelect<TResult>;
_selectExpression = resultSelector.Body; _selectExpression = resultSelector.Body;
(_orm.CodeFirst as CodeFirstProvider).dicSyced.TryAdd(typeof(TResult).FullName, true); (_orm.CodeFirst as CodeFirstProvider).dicSyced.TryAdd(typeof(TResult), true);
var ret = _orm.Select<TResult>() as Select1Provider<TResult>; var ret = _orm.Select<TResult>() as Select1Provider<TResult>;
Select0Provider<ISelect<T1>, T1>.CopyData(this, ret, null); Select0Provider<ISelect<T1>, T1>.CopyData(this, ret, null);
return ret; return ret;
@ -243,7 +243,7 @@ namespace FreeSql.Internal.CommonProvider
), SelectTableInfoType.InnerJoin); ), SelectTableInfoType.InnerJoin);
if (typeof(TResult) == typeof(T1)) return this as ISelect<TResult>; if (typeof(TResult) == typeof(T1)) return this as ISelect<TResult>;
_selectExpression = resultSelector.Body; _selectExpression = resultSelector.Body;
(_orm.CodeFirst as CodeFirstProvider).dicSyced.TryAdd(typeof(TResult).FullName, true); (_orm.CodeFirst as CodeFirstProvider).dicSyced.TryAdd(typeof(TResult), true);
var ret = _orm.Select<TResult>() as Select1Provider<TResult>; var ret = _orm.Select<TResult>() as Select1Provider<TResult>;
Select0Provider<ISelect<T1>, T1>.CopyData(this, ret, null); Select0Provider<ISelect<T1>, T1>.CopyData(this, ret, null);
return ret; return ret;
@ -275,7 +275,7 @@ namespace FreeSql.Internal.CommonProvider
} }
if (typeof(TResult) == typeof(T1)) return this as ISelect<TResult>; if (typeof(TResult) == typeof(T1)) return this as ISelect<TResult>;
_selectExpression = resultSelector.Body; _selectExpression = resultSelector.Body;
(_orm.CodeFirst as CodeFirstProvider).dicSyced.TryAdd(typeof(TResult).FullName, true); (_orm.CodeFirst as CodeFirstProvider).dicSyced.TryAdd(typeof(TResult), true);
var ret = _orm.Select<TResult>() as Select1Provider<TResult>; var ret = _orm.Select<TResult>() as Select1Provider<TResult>;
Select0Provider<ISelect<T1>, T1>.CopyData(this, ret, null); Select0Provider<ISelect<T1>, T1>.CopyData(this, ret, null);
return ret; return ret;