Optimize CodeFirst

This commit is contained in:
sunkaixuan
2024-06-22 12:51:26 +08:00
parent fce7e40a41
commit 490e28ef3a
2 changed files with 11 additions and 5 deletions

View File

@@ -82,7 +82,7 @@ namespace SqlSugar
{
MappingTableList oldTableList = CopyMappingTalbe();
//this.Context.Utilities.RemoveCacheAll();
this.Context.InitMappingInfoNoCache(entityType);
var entityInfo=this.Context.GetEntityNoCacheInitMappingInfo(entityType);
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
{
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
@@ -93,13 +93,13 @@ namespace SqlSugar
{
var executeResult = Context.Ado.UseTran(() =>
{
Execute(entityType);
Execute(entityType,entityInfo);
});
Check.Exception(!executeResult.IsSuccess, executeResult.ErrorMessage);
}
else
{
Execute(entityType);
Execute(entityType, entityInfo);
}
RestMappingTables(oldTableList);
@@ -240,9 +240,9 @@ namespace SqlSugar
db.DbMaintenance.DropTable(tempTableName);
}
}
protected virtual void Execute(Type entityType)
protected virtual void Execute(Type entityType,EntityInfo entityInfo)
{
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
//var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(entityType);
if (entityInfo.Discrimator.HasValue())
{
Check.ExceptionEasy(!Regex.IsMatch(entityInfo.Discrimator, @"^(?:\w+:\w+)(?:,\w+:\w+)*$"), "The format should be type:cat for this type, and if there are multiple, it can be FieldName:cat,FieldName2:dog ", "格式错误应该是type:cat这种格式如果是多个可以FieldName:cat,FieldName2:dog不要有空格");

View File

@@ -168,6 +168,12 @@ namespace SqlSugar
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(type);
InitMappingInfo(entityInfo);
}
public EntityInfo GetEntityNoCacheInitMappingInfo(Type type)
{
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(type);
InitMappingInfo(entityInfo);
return entityInfo;
}
//private EntityInfo CopyEntityInfo(EntityInfo entityInfo)
//{
// EntityInfo result = new EntityInfo()