mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
Update exp to sql
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user