mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 增加 ICodeFirst.SyncStructure 强制同步参数 isForceSync;#412
This commit is contained in:
@ -3065,13 +3065,14 @@
|
||||
</summary>
|
||||
<param name="entityTypes"></param>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.SyncStructure(System.Type,System.String)">
|
||||
<member name="M:FreeSql.ICodeFirst.SyncStructure(System.Type,System.String,System.Boolean)">
|
||||
<summary>
|
||||
同步实体类型到数据库(指定表名)<para></para>
|
||||
注意:生产环境中谨慎使用
|
||||
</summary>
|
||||
<param name="entityType">实体类型</param>
|
||||
<param name="tableName">指定表名对比</param>
|
||||
<param name="isForceSync">强制同步结构,无视缓存每次都同步</param>
|
||||
</member>
|
||||
<member name="M:FreeSql.ICodeFirst.GetDbInfo(System.Type)">
|
||||
<summary>
|
||||
|
@ -80,7 +80,8 @@ namespace FreeSql
|
||||
/// </summary>
|
||||
/// <param name="entityType">实体类型</param>
|
||||
/// <param name="tableName">指定表名对比</param>
|
||||
void SyncStructure(Type entityType, string tableName);
|
||||
/// <param name="isForceSync">强制同步结构,无视缓存每次都同步</param>
|
||||
void SyncStructure(Type entityType, string tableName, bool isForceSync = false);
|
||||
|
||||
/// <summary>
|
||||
/// 根据 System.Type 获取数据库信息
|
||||
|
@ -69,7 +69,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
static object syncStructureLock = new object();
|
||||
object _dicSycedLock = new object();
|
||||
ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>> _dicSynced = new ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>>();
|
||||
public ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>> _dicSynced = new ConcurrentDictionary<Type, ConcurrentDictionary<string, bool>>();
|
||||
internal ConcurrentDictionary<string, bool> _dicSycedGetOrAdd(Type entityType)
|
||||
{
|
||||
if (_dicSynced.TryGetValue(entityType, out var trydic) == false)
|
||||
@ -85,8 +85,12 @@ namespace FreeSql.Internal.CommonProvider
|
||||
this.SyncStructure(new TypeAndName(typeof(TEntity), ""));
|
||||
public void SyncStructure(params Type[] entityTypes) =>
|
||||
this.SyncStructure(entityTypes?.Distinct().Select(a => new TypeAndName(a, "")).ToArray());
|
||||
public void SyncStructure(Type entityType, string tableName) =>
|
||||
this.SyncStructure(new TypeAndName(entityType, GetTableNameLowerOrUpper(tableName)));
|
||||
public void SyncStructure(Type entityType, string tableName, bool isForceSync)
|
||||
{
|
||||
tableName = GetTableNameLowerOrUpper(tableName);
|
||||
if (isForceSync && _dicSynced.TryGetValue(entityType, out var dic)) dic.TryRemove(tableName, out var old);
|
||||
this.SyncStructure(new TypeAndName(entityType, tableName));
|
||||
}
|
||||
protected void SyncStructure(params TypeAndName[] objects)
|
||||
{
|
||||
if (objects == null) return;
|
||||
|
Reference in New Issue
Block a user