|
|
@ -10,6 +10,7 @@ namespace SqlSugar |
|
|
|
public partial class CodeFirstProvider : ICodeFirst |
|
|
|
{ |
|
|
|
#region Properties
|
|
|
|
internal static object LockObject = new object(); |
|
|
|
public virtual SqlSugarProvider Context { get; set; } |
|
|
|
protected bool IsBackupTable { get; set; } |
|
|
|
protected int MaxBackupDataRows { get; set; } |
|
|
@ -47,7 +48,10 @@ namespace SqlSugar |
|
|
|
|
|
|
|
public virtual void InitTables(Type entityType) |
|
|
|
{ |
|
|
|
|
|
|
|
//Prevent concurrent requests if used in your program
|
|
|
|
lock (CodeFirstProvider.LockObject) |
|
|
|
{ |
|
|
|
MappingTableList oldTableList = CopyMappingTalbe(); |
|
|
|
//this.Context.Utilities.RemoveCacheAll();
|
|
|
|
this.Context.InitMappingInfoNoCache(entityType); |
|
|
|
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions()) |
|
|
@ -69,7 +73,11 @@ namespace SqlSugar |
|
|
|
Execute(entityType); |
|
|
|
} |
|
|
|
|
|
|
|
RestMappingTables(oldTableList); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void InitTables<T>() |
|
|
|
{ |
|
|
|
InitTables(typeof(T)); |
|
|
@ -114,6 +122,10 @@ namespace SqlSugar |
|
|
|
{ |
|
|
|
MappingTables.Add(type,newTableName); |
|
|
|
} |
|
|
|
else if (!MappingTables.ContainsKey(type)) |
|
|
|
{ |
|
|
|
MappingTables[type]= newTableName; |
|
|
|
} |
|
|
|
return this; |
|
|
|
} |
|
|
|
public ICodeFirst As<T>(string newTableName) |
|
|
@ -443,6 +455,28 @@ namespace SqlSugar |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Helper methods
|
|
|
|
private void RestMappingTables(MappingTableList oldTableList) |
|
|
|
{ |
|
|
|
this.Context.MappingTables.Clear(); |
|
|
|
foreach (var table in oldTableList) |
|
|
|
{ |
|
|
|
this.Context.MappingTables.Add(table.EntityName, table.DbTableName); |
|
|
|
} |
|
|
|
} |
|
|
|
private MappingTableList CopyMappingTalbe() |
|
|
|
{ |
|
|
|
MappingTableList oldTableList = new MappingTableList(); |
|
|
|
if (this.Context.MappingTables == null) |
|
|
|
{ |
|
|
|
this.Context.MappingTables = new MappingTableList(); |
|
|
|
} |
|
|
|
foreach (var table in this.Context.MappingTables) |
|
|
|
{ |
|
|
|
oldTableList.Add(table.EntityName, table.DbTableName); |
|
|
|
} |
|
|
|
return oldTableList; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual string GetCreateTableString(EntityInfo entityInfo) |
|
|
|
{ |
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|