mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-27 16:50:33 +08:00
Update exp to sql
This commit is contained in:
@@ -457,12 +457,14 @@ namespace SqlSugar
|
||||
internal static List<NewExpressionInfo> GetNewDynamicexpressionInfos(Expression item, ExpressionContext context)
|
||||
{
|
||||
List<NewExpressionInfo> result = new List<NewExpressionInfo>();
|
||||
int i = 0;
|
||||
foreach (var binding in ((NewExpression)item).Arguments)
|
||||
{
|
||||
NewExpressionInfo additem = new NewExpressionInfo();
|
||||
var keys = ((NewExpression)item).Members;
|
||||
if (binding is MemberExpression)
|
||||
{
|
||||
var member = (MemberExpression)binding;
|
||||
var member = (MemberExpression)binding;
|
||||
//var memberAssignment = binding;
|
||||
//NewExpressionInfo additem = new NewExpressionInfo();
|
||||
additem.RightName = member.Member.Name;
|
||||
@@ -473,6 +475,20 @@ namespace SqlSugar
|
||||
//additem.Value = "";
|
||||
result.Add(additem);
|
||||
}
|
||||
else if (binding is ConstantExpression)
|
||||
{
|
||||
var value = ((ConstantExpression)binding).Value;
|
||||
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 = UtilMethods.GetSqlValue(value);
|
||||
//additem.Value = "";
|
||||
result.Add(additem);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@ namespace SqlSugar
|
||||
public string RightName { get; set; }
|
||||
public string RightDbName { get; set; }
|
||||
public string ShortName { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,13 +512,22 @@ namespace SqlSugar
|
||||
{
|
||||
//var property=item.Type.GetProperties().Where(it => it.Name == newExpressionInfo.l).First();
|
||||
//asName = GetAsName(item, newExpressionInfo.ShortName, property);
|
||||
mappingKeys.Add("Single_"+newExpressionInfo.LeftNameName,asName + "." + newExpressionInfo.RightDbName );
|
||||
CallContextThread<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
|
||||
CallContextAsync<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(
|
||||
this.Context.SqlTranslationLeft + asName + "." + newExpressionInfo.RightDbName + this.Context.SqlTranslationRight,
|
||||
newExpressionInfo.RightDbName
|
||||
));
|
||||
mappingKeys.Add("Single_" + newExpressionInfo.LeftNameName, asName + "." + newExpressionInfo.RightDbName);
|
||||
if (newExpressionInfo.Type == nameof(ConstantExpression))
|
||||
{
|
||||
CallContextThread<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} ");
|
||||
}
|
||||
else
|
||||
{
|
||||
CallContextThread<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
|
||||
CallContextAsync<Dictionary<string, string>>.SetData("Exp_Select_Mapping_Key", mappingKeys);
|
||||
parameter.Context.Result.Append(this.Context.GetAsString(
|
||||
this.Context.SqlTranslationLeft + asName + "." + newExpressionInfo.RightDbName + this.Context.SqlTranslationRight,
|
||||
newExpressionInfo.RightDbName
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -539,6 +539,26 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetSqlValue(object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
else if (UtilMethods.IsNumber(value.GetType().Name))
|
||||
{
|
||||
return value.ObjToString();
|
||||
}
|
||||
else if (value is DateTime)
|
||||
{
|
||||
return UtilMethods.GetConvertValue(value) + "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return value.ToSqlValue();
|
||||
}
|
||||
}
|
||||
|
||||
public static void DataInoveByExpresson<Type>(Type[] datas, MethodCallExpression callExpresion)
|
||||
{
|
||||
var methodInfo = callExpresion.Method;
|
||||
|
||||
Reference in New Issue
Block a user