Browse Source

Update exp to sql

SqlSugar5
sunkaixuan 2 years ago
parent
commit
33da4bf900
  1. 21
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs
  2. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs
  3. 5
      Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs

21
Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

@ -454,17 +454,24 @@ namespace SqlSugar
}
return result;
}
internal static List<NewExpressionInfo> GetNewDynamicexpressionInfos(Expression item)
internal static List<NewExpressionInfo> GetNewDynamicexpressionInfos(Expression item, ExpressionContext context)
{
List<NewExpressionInfo> result = new List<NewExpressionInfo>();
foreach (var binding in ((NewExpression)item).Arguments)
{
//var memberAssignment = binding;
//NewExpressionInfo additem = new NewExpressionInfo();
//additem.Name = memberAssignment.Member.Name;
//additem.ShortName = (memberAssignment.Expression as MemberExpression).Expression + "";
//additem.Value = "";
//result.Add(additem);
NewExpressionInfo additem = new NewExpressionInfo();
if (binding is MemberExpression)
{
var member = (MemberExpression)binding;
//var memberAssignment = binding;
//NewExpressionInfo additem = new NewExpressionInfo();
additem.RightName = member.Member.Name;
additem.ShortName = member.Expression + "";
additem.RightName = member.Member.Name;
additem.RightDbName = context.GetDbColumnName(member.Type.Name, additem.RightName);
//additem.Value = "";
result.Add(additem);
}
}
return result;
}

2
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs

@ -469,7 +469,7 @@ namespace SqlSugar
}
else
{
newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item, this.Context);
newExpressionInfos = ExpressionTool.GetNewDynamicexpressionInfos(item, this.Context);
}
foreach (NewExpressionInfo newExpressionInfo in newExpressionInfos)
{

5
Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs

@ -436,6 +436,11 @@ namespace SqlSugar
{
var key = typeName + "." + name;
var info = readerValues.Select(it => it.Key).FirstOrDefault(it => it.ToLower() == key.ToLower());
if (info == null && typeName !=null && typeName.Contains("<>f__AnonymousType"))
{
key = item.Name + "." + name;
info = readerValues.Select(it => it.Key).FirstOrDefault(it => it.ToLower() == key.ToLower());
}
var oldInfo = info;
if (mappingKeys!=null&&mappingKeys.ContainsKey(item.Name))
{

Loading…
Cancel
Save