Update exp to sql

This commit is contained in:
sunkaixuan
2022-08-02 20:19:14 +08:00
parent 9faf62c590
commit 42ef42a97d
4 changed files with 80 additions and 1 deletions

View File

@@ -430,5 +430,43 @@ namespace SqlSugar
{
return item is UnaryExpression && item.NodeType == ExpressionType.Convert;
}
internal static List<NewExpressionInfo> GetNewexpressionInfos(Expression item,ExpressionContext context)
{
List<NewExpressionInfo> result = new List<NewExpressionInfo>();
foreach (MemberBinding binding in ((MemberInitExpression)item).Bindings)
{
if (binding.BindingType != MemberBindingType.Assignment)
{
throw new NotSupportedException();
}
MemberAssignment memberAssignment = (MemberAssignment)binding;
NewExpressionInfo additem = new NewExpressionInfo();
if ((memberAssignment.Expression is MemberExpression))
{
additem.LeftNameName = memberAssignment.Member.Name;
var member = (memberAssignment.Expression as MemberExpression).Expression;
additem.ShortName = member + "";
additem.RightName = (memberAssignment.Expression as MemberExpression).Member.Name;
additem.RightDbName = context.GetDbColumnName(member.Type.Name, additem.RightName);
result.Add(additem);
}
}
return result;
}
internal static List<NewExpressionInfo> GetNewDynamicexpressionInfos(Expression item)
{
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);
}
return result;
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
internal class NewExpressionInfo
{
public string LeftNameName { get; set; }
public string RightName { get; set; }
public string RightDbName { get; set; }
public string ShortName { get; set; }
}
}

View File

@@ -460,7 +460,31 @@ namespace SqlSugar
CallContextThread<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
CallContextAsync<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
this.Expression = item;
asName = GetAsNameResolveAnObject(parameter, item, asName, isSameType);
if (this.Context.IsJoin&& (item is MemberInitExpression|| item is NewExpression))
{
List<NewExpressionInfo> newExpressionInfos = new List<NewExpressionInfo>();
if (item is MemberInitExpression)
{
newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item,this.Context);
}
else
{
newExpressionInfos = ExpressionTool.GetNewexpressionInfos(item, this.Context);
}
foreach (NewExpressionInfo newExpressionInfo in newExpressionInfos)
{
//var property=item.Type.GetProperties().Where(it => it.Name == newExpressionInfo.l).First();
//asName = GetAsName(item, newExpressionInfo.ShortName, property);
parameter.Context.Result.Append(this.Context.GetAsString(
this.Context.SqlTranslationLeft+asName + "." + newExpressionInfo.RightDbName+this.Context.SqlTranslationRight,
newExpressionInfo.ShortName+"."+newExpressionInfo.RightDbName
));
}
}
else
{
asName = GetAsNameResolveAnObject(parameter, item, asName, isSameType);
}
}
else if (item.Type == UtilConstants.BoolType && item is MethodCallExpression && IsNotCaseExpression(item))
{

View File

@@ -125,6 +125,7 @@
<Compile Include="Abstract\UpdateProvider\SplitTableUpdateByObjectProvider.cs" />
<Compile Include="Entities\DbFastestProperties.cs" />
<Compile Include="Entities\DeleteNavOptions.cs" />
<Compile Include="ExpressionsToSql\Common\NewExpressionInfo.cs" />
<Compile Include="ExpressionsToSql\Subquery\Items\SubWithNoLock.cs" />
<Compile Include="ExpressionsToSql\Subquery\Items\SubEnableTableFilter.cs" />
<Compile Include="Json2Sql\Entities\JsonDeleteResult.cs" />