mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-01 10:10:16 +08:00
Update exp to sql
This commit is contained in:
parent
8df44bed89
commit
04b7f0c667
@ -431,7 +431,7 @@ namespace SqlSugar
|
|||||||
return item is UnaryExpression && item.NodeType == ExpressionType.Convert;
|
return item is UnaryExpression && item.NodeType == ExpressionType.Convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static List<NewExpressionInfo> GetNewexpressionInfos(Expression item,ExpressionContext context)
|
internal static List<NewExpressionInfo> GetNewexpressionInfos(Expression item,ExpressionContext context, BaseResolve baseResolve)
|
||||||
{
|
{
|
||||||
List<NewExpressionInfo> result = new List<NewExpressionInfo>();
|
List<NewExpressionInfo> result = new List<NewExpressionInfo>();
|
||||||
foreach (MemberBinding binding in ((MemberInitExpression)item).Bindings)
|
foreach (MemberBinding binding in ((MemberInitExpression)item).Bindings)
|
||||||
@ -442,7 +442,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
MemberAssignment memberAssignment = (MemberAssignment)binding;
|
MemberAssignment memberAssignment = (MemberAssignment)binding;
|
||||||
NewExpressionInfo additem = new NewExpressionInfo();
|
NewExpressionInfo additem = new NewExpressionInfo();
|
||||||
if ((memberAssignment.Expression is MemberExpression))
|
if (memberAssignment.Expression is MemberExpression)
|
||||||
{
|
{
|
||||||
additem.LeftNameName = memberAssignment.Member.Name;
|
additem.LeftNameName = memberAssignment.Member.Name;
|
||||||
var member = (memberAssignment.Expression as MemberExpression).Expression;
|
var member = (memberAssignment.Expression as MemberExpression).Expression;
|
||||||
@ -451,10 +451,37 @@ namespace SqlSugar
|
|||||||
additem.RightDbName = context.GetDbColumnName(member.Type.Name, additem.RightName);
|
additem.RightDbName = context.GetDbColumnName(member.Type.Name, additem.RightName);
|
||||||
result.Add(additem);
|
result.Add(additem);
|
||||||
}
|
}
|
||||||
|
else if (memberAssignment.Expression is ConstantExpression)
|
||||||
|
{
|
||||||
|
var value = ((ConstantExpression)memberAssignment.Expression).Value;
|
||||||
|
//var leftInfo = keys[i];
|
||||||
|
additem.Type = nameof(ConstantExpression);
|
||||||
|
additem.RightName = memberAssignment.Member.Name;
|
||||||
|
additem.ShortName = memberAssignment.Member.Name;
|
||||||
|
additem.RightName = memberAssignment.Member.Name;
|
||||||
|
additem.LeftNameName = memberAssignment.Member.Name;
|
||||||
|
additem.RightDbName = UtilMethods.GetSqlValue(value);
|
||||||
|
//additem.Value = "";
|
||||||
|
result.Add(additem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var value = baseResolve.GetNewExpressionValue(memberAssignment.Expression);
|
||||||
|
//var leftInfo = keys[i];
|
||||||
|
additem.Type = nameof(ConstantExpression);
|
||||||
|
additem.RightName = memberAssignment.Member.Name;
|
||||||
|
additem.ShortName = memberAssignment.Member.Name;
|
||||||
|
additem.RightName = memberAssignment.Member.Name;
|
||||||
|
additem.LeftNameName = memberAssignment.Member.Name;
|
||||||
|
additem.RightDbName = value;
|
||||||
|
//additem.Value = "";
|
||||||
|
result.Add(additem);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
internal static List<NewExpressionInfo> GetNewDynamicexpressionInfos(Expression item, ExpressionContext context)
|
internal static List<NewExpressionInfo> GetNewDynamicexpressionInfos(Expression item, ExpressionContext context, BaseResolve baseResolve)
|
||||||
{
|
{
|
||||||
List<NewExpressionInfo> result = new List<NewExpressionInfo>();
|
List<NewExpressionInfo> result = new List<NewExpressionInfo>();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -488,6 +515,19 @@ namespace SqlSugar
|
|||||||
//additem.Value = "";
|
//additem.Value = "";
|
||||||
result.Add(additem);
|
result.Add(additem);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var value = baseResolve.GetNewExpressionValue(binding);
|
||||||
|
var leftInfo = keys[i];
|
||||||
|
additem.Type = nameof(ConstantExpression);
|
||||||
|
additem.RightName = leftInfo.Name;
|
||||||
|
additem.ShortName = leftInfo.Name;
|
||||||
|
additem.RightName = leftInfo.Name;
|
||||||
|
additem.LeftNameName = leftInfo.Name;
|
||||||
|
additem.RightDbName = value;
|
||||||
|
//additem.Value = "";
|
||||||
|
result.Add(additem);
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -480,11 +480,11 @@ namespace SqlSugar
|
|||||||
List<NewExpressionInfo> newExpressionInfos = new List<NewExpressionInfo>();
|
List<NewExpressionInfo> newExpressionInfos = new List<NewExpressionInfo>();
|
||||||
if (item is MemberInitExpression)
|
if (item is MemberInitExpression)
|
||||||
{
|
{
|
||||||
newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item,this.Context);
|
newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item,this.Context,this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newExpressionInfos = ExpressionTool.GetNewDynamicexpressionInfos(item, this.Context);
|
newExpressionInfos = ExpressionTool.GetNewDynamicexpressionInfos(item, this.Context,this);
|
||||||
}
|
}
|
||||||
foreach (NewExpressionInfo newExpressionInfo in newExpressionInfos)
|
foreach (NewExpressionInfo newExpressionInfo in newExpressionInfos)
|
||||||
{
|
{
|
||||||
@ -501,23 +501,23 @@ namespace SqlSugar
|
|||||||
List<NewExpressionInfo> newExpressionInfos = new List<NewExpressionInfo>();
|
List<NewExpressionInfo> newExpressionInfos = new List<NewExpressionInfo>();
|
||||||
if (item is MemberInitExpression)
|
if (item is MemberInitExpression)
|
||||||
{
|
{
|
||||||
newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item, this.Context);
|
newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item, this.Context,this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newExpressionInfos = ExpressionTool.GetNewDynamicexpressionInfos(item, this.Context);
|
newExpressionInfos = ExpressionTool.GetNewDynamicexpressionInfos(item, this.Context,this);
|
||||||
}
|
}
|
||||||
mappingKeys = new Dictionary<string, string>();
|
mappingKeys = new Dictionary<string, string>();
|
||||||
foreach (NewExpressionInfo newExpressionInfo in newExpressionInfos)
|
foreach (NewExpressionInfo newExpressionInfo in newExpressionInfos)
|
||||||
{
|
{
|
||||||
//var property=item.Type.GetProperties().Where(it => it.Name == newExpressionInfo.l).First();
|
//var property=item.Type.GetProperties().Where(it => it.Name == newExpressionInfo.l).First();
|
||||||
//asName = GetAsName(item, newExpressionInfo.ShortName, property);
|
//asName = GetAsName(item, newExpressionInfo.ShortName, property);
|
||||||
mappingKeys.Add("Single_" + newExpressionInfo.LeftNameName, asName + "." + newExpressionInfo.RightDbName);
|
mappingKeys.Add("Single_" + newExpressionInfo.LeftNameName, asName + "." + newExpressionInfo.LeftNameName);
|
||||||
if (newExpressionInfo.Type == nameof(ConstantExpression))
|
if (newExpressionInfo.Type == nameof(ConstantExpression))
|
||||||
{
|
{
|
||||||
CallContextThread<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
|
CallContextThread<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
|
||||||
CallContextAsync<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
|
CallContextAsync<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
|
||||||
parameter.Context.Result.Append($" {newExpressionInfo.RightDbName} as { this.Context.SqlTranslationLeft}{asName}.{newExpressionInfo.LeftNameName}{ this.Context.SqlTranslationRight} ");
|
parameter.Context.Result.Append($" {newExpressionInfo.RightDbName} AS { this.Context.SqlTranslationLeft}{asName}.{newExpressionInfo.LeftNameName}{ this.Context.SqlTranslationRight} ");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user