diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs index 0769b5feb..8e001638a 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs @@ -454,17 +454,24 @@ namespace SqlSugar } return result; } - internal static List GetNewDynamicexpressionInfos(Expression item) + internal static List GetNewDynamicexpressionInfos(Expression item, ExpressionContext context) { List result = new List(); 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; } diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs index 962387ced..7849b7597 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs +++ b/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) { diff --git a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs b/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs index 8687f0d3e..e4509564b 100644 --- a/Src/Asp.Net/SqlSugar/Infrastructure/ContextMethods.cs +++ b/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)) {