Browse Source

Update .net core project

SqlSugar5
sunkaixuan 2 years ago
parent
commit
ca4e5c5807
  1. 86
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs
  2. 9
      Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs
  3. 14
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

86
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarAccessory.cs

@ -160,55 +160,55 @@ namespace SqlSugar
var result = this.Context.EntityMaintenance.GetEntityInfo(type);
return result;
});
var copyObj = CopyEntityInfo(entityInfo);
InitMappingInfo(copyObj);
//var copyObj = CopyEntityInfo(entityInfo);
InitMappingInfo(entityInfo);
}
public void InitMappingInfoNoCache(Type type)
{
var entityInfo = this.Context.EntityMaintenance.GetEntityInfoNoCache(type);
InitMappingInfo(entityInfo);
}
private EntityInfo CopyEntityInfo(EntityInfo entityInfo)
{
EntityInfo result = new EntityInfo()
{
DbTableName = entityInfo.DbTableName,
EntityName = entityInfo.EntityName,
Type = entityInfo.Type
};
List<EntityColumnInfo> columns = new List<EntityColumnInfo>();
if (entityInfo.Columns.HasValue())
{
foreach (var item in entityInfo.Columns)
{
EntityColumnInfo column = new EntityColumnInfo()
{
ColumnDescription = item.ColumnDescription,
DataType = item.DataType,
DbColumnName = item.DbColumnName,
DbTableName = item.DbTableName,
DecimalDigits = item.DecimalDigits,
DefaultValue = item.DefaultValue,
EntityName = item.EntityName,
IsIdentity = item.IsIdentity,
IsIgnore = item.IsIgnore,
IsNullable = item.IsNullable,
IsOnlyIgnoreInsert = item.IsOnlyIgnoreInsert,
IsPrimarykey = item.IsPrimarykey,
Length = item.Length,
OldDbColumnName = item.OldDbColumnName,
OracleSequenceName = item.OracleSequenceName,
PropertyInfo = item.PropertyInfo,
PropertyName = item.PropertyName,
IsArray=item.IsArray,
IsJson=item.IsJson
};
columns.Add(item);
}
}
result.Columns = columns;
return result;
}
//private EntityInfo CopyEntityInfo(EntityInfo entityInfo)
//{
// EntityInfo result = new EntityInfo()
// {
// DbTableName = entityInfo.DbTableName,
// EntityName = entityInfo.EntityName,
// Type = entityInfo.Type
// };
// List<EntityColumnInfo> columns = new List<EntityColumnInfo>();
// if (entityInfo.Columns.HasValue())
// {
// foreach (var item in entityInfo.Columns)
// {
// EntityColumnInfo column = new EntityColumnInfo()
// {
// ColumnDescription = item.ColumnDescription,
// DataType = item.DataType,
// DbColumnName = item.DbColumnName,
// DbTableName = item.DbTableName,
// DecimalDigits = item.DecimalDigits,
// DefaultValue = item.DefaultValue,
// EntityName = item.EntityName,
// IsIdentity = item.IsIdentity,
// IsIgnore = item.IsIgnore,
// IsNullable = item.IsNullable,
// IsOnlyIgnoreInsert = item.IsOnlyIgnoreInsert,
// IsPrimarykey = item.IsPrimarykey,
// Length = item.Length,
// OldDbColumnName = item.OldDbColumnName,
// OracleSequenceName = item.OracleSequenceName,
// PropertyInfo = item.PropertyInfo,
// PropertyName = item.PropertyName,
// IsArray=item.IsArray,
// IsJson=item.IsJson
// };
// columns.Add(item);
// }
// }
// result.Columns = columns;
// return result;
//}
private void InitMappingInfo(EntityInfo entityInfo)
{

9
Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableHelper.cs

@ -106,14 +106,19 @@ namespace SqlSugar
var diffColumns = FastCopy.GetDiff(item, (T)trackingData.Value);
if (diffColumns.Count > 0)
{
var pks =EntityInfo.Columns
var pks = EntityInfo.Columns
.Where(it => it.IsPrimarykey).Select(it => it.PropertyName).ToList();
diffColumns=diffColumns.Where(it => !pks.Contains(it)).ToList();
diffColumns = diffColumns.Where(it => !pks.Contains(it)).ToList();
if (diffColumns.Count > 0)
{
this.UpdateColumns(diffColumns.ToArray());
}
}
else
{
this.UpdateObjs = new T [] { null };
this.UpdateBuilder.DbColumnInfoList = new List<DbColumnInfo>();
}
}
}

14
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/BinaryExpressionResolve.cs

@ -162,6 +162,20 @@ namespace SqlSugar
{
var leftSql = GetNewExpressionValue(expression.Left);
var rightExpression = expression.Right as MethodCallExpression;
if (rightExpression.Arguments[0] is LambdaExpression)
{
if ((rightExpression.Arguments[0] as LambdaExpression).Parameters?.Count > 0)
{
foreach (var item in (rightExpression.Arguments[0] as LambdaExpression).Parameters)
{
if (this.Context.InitMappingInfo != null)
{
this.Context.InitMappingInfo(item.Type);
this.Context.RefreshMapping();
}
}
}
}
var selector = GetNewExpressionValue(rightExpression.Arguments[0]);
var selectorExp = rightExpression.Arguments[0];
if (selector.Contains(".") && selectorExp is LambdaExpression)

Loading…
Cancel
Save