mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Update CodeFirst
This commit is contained in:
@@ -47,8 +47,8 @@ namespace SqlSugar
|
||||
public virtual void InitTables(Type entityType)
|
||||
{
|
||||
|
||||
this.Context.Utilities.RemoveCacheAll();
|
||||
this.Context.InitMappingInfo(entityType);
|
||||
//this.Context.Utilities.RemoveCacheAll();
|
||||
this.Context.InitMappingInfoNoCache(entityType);
|
||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||
{
|
||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||
@@ -114,7 +114,7 @@ namespace SqlSugar
|
||||
#region Core Logic
|
||||
protected virtual void Execute(Type entityType)
|
||||
{
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(entityType);
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
|
||||
if (this.DefultLength > 0)
|
||||
{
|
||||
foreach (var item in entityInfo.Columns)
|
||||
@@ -139,7 +139,7 @@ namespace SqlSugar
|
||||
this.Context.MappingTables.Add(entityInfo.EntityName,tableName);
|
||||
entityInfo.DbTableName = tableName;
|
||||
entityInfo.Columns.ForEach(it => { it.DbTableName = tableName; });
|
||||
var isAny = this.Context.DbMaintenance.IsAnyTable(tableName);
|
||||
var isAny = this.Context.DbMaintenance.IsAnyTable(tableName,false);
|
||||
if (isAny&&entityInfo.IsDisabledUpdateAll)
|
||||
{
|
||||
return;
|
||||
@@ -175,7 +175,7 @@ namespace SqlSugar
|
||||
//Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Multiple primary keys do not support modifications");
|
||||
|
||||
var tableName = GetTableName(entityInfo);
|
||||
var dbColumns = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName);
|
||||
var dbColumns = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName,false);
|
||||
ConvertColumns(dbColumns);
|
||||
var entityColumns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
var dropColumns = dbColumns
|
||||
|
@@ -20,6 +20,12 @@ namespace SqlSugar
|
||||
string cacheKey = "GetEntityInfo" + type.FullName;
|
||||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
() =>
|
||||
{
|
||||
return GetEntityInfoNoCache(type);
|
||||
});
|
||||
}
|
||||
|
||||
public EntityInfo GetEntityInfoNoCache(Type type)
|
||||
{
|
||||
EntityInfo result = new EntityInfo();
|
||||
var sugarAttributeInfo = type.GetTypeInfo().GetCustomAttributes(typeof(SugarTable), true).Where(it => it is SugarTable).SingleOrDefault();
|
||||
@@ -31,20 +37,21 @@ namespace SqlSugar
|
||||
result.IsDisabledUpdateAll = sugarTable.IsDisabledUpdateAll;
|
||||
result.IsDisabledDelete = sugarTable.IsDisabledDelete;
|
||||
}
|
||||
if (this.Context.Context.CurrentConnectionConfig.ConfigureExternalServices != null && this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService != null) {
|
||||
if (this.Context.Context.CurrentConnectionConfig.ConfigureExternalServices != null && this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService != null)
|
||||
{
|
||||
if (result.DbTableName == null)
|
||||
{
|
||||
result.DbTableName = type.Name;
|
||||
}
|
||||
this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService(type,result);
|
||||
this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService(type, result);
|
||||
}
|
||||
result.Type = type;
|
||||
result.EntityName = result.Type.Name;
|
||||
result.Columns = new List<EntityColumnInfo>();
|
||||
SetColumns(result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
public string GetTableName<T>()
|
||||
{
|
||||
var typeName = typeof(T).Name;
|
||||
|
@@ -162,7 +162,11 @@ namespace SqlSugar
|
||||
var copyObj = CopyEntityInfo(entityInfo);
|
||||
InitMappingInfo(copyObj);
|
||||
}
|
||||
|
||||
public void InitMappingInfoNoCache(Type type)
|
||||
{
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(type);
|
||||
InitMappingInfo(entityInfo);
|
||||
}
|
||||
private EntityInfo CopyEntityInfo(EntityInfo entityInfo)
|
||||
{
|
||||
EntityInfo result = new EntityInfo()
|
||||
|
@@ -14,7 +14,7 @@ namespace SqlSugar
|
||||
Check.Exception(entityInfo.Columns.Where(it => it.IsPrimarykey).Count() > 1, "Use Code First ,The primary key must not exceed 1");
|
||||
|
||||
var tableName = GetTableName(entityInfo);
|
||||
var dbColumns = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName);
|
||||
var dbColumns = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName,false);
|
||||
ConvertColumns(dbColumns);
|
||||
var entityColumns = entityInfo.Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
var dropColumns = dbColumns
|
||||
|
Reference in New Issue
Block a user