mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-15 23:13:42 +08:00
Updater Expression
This commit is contained in:
parent
dc3dbd76ea
commit
250992de65
@ -23,6 +23,7 @@ namespace OrmTest.UnitTest
|
|||||||
{
|
{
|
||||||
single();
|
single();
|
||||||
single2();
|
single2();
|
||||||
|
single3();
|
||||||
Multiple();
|
Multiple();
|
||||||
singleDynamic();
|
singleDynamic();
|
||||||
MultipleDynamic();
|
MultipleDynamic();
|
||||||
@ -101,6 +102,17 @@ namespace OrmTest.UnitTest
|
|||||||
new SugarParameter("@Id2",11 ) },
|
new SugarParameter("@Id2",11 ) },
|
||||||
"Select.single Error");
|
"Select.single Error");
|
||||||
}
|
}
|
||||||
|
private void single3(int p = 1)
|
||||||
|
{
|
||||||
|
Expression<Func<Student, object>> exp = it => new DataTestInfo() { Datetime1=DateTime.Now, String=it.Name};
|
||||||
|
ExpressionContext expContext = new ExpressionContext();
|
||||||
|
expContext.Resolve(exp, ResolveExpressType.SelectSingle);
|
||||||
|
var selectorValue = expContext.Result.GetString();
|
||||||
|
var pars = expContext.Parameters;
|
||||||
|
base.Check(
|
||||||
|
@" @constant0 AS [Datetime1] , [Name] AS [String] ", null,selectorValue,null,
|
||||||
|
"Select.single3 Error");
|
||||||
|
}
|
||||||
|
|
||||||
private void singleDynamic()
|
private void singleDynamic()
|
||||||
{
|
{
|
||||||
|
@ -216,7 +216,7 @@ namespace SqlSugar
|
|||||||
return methodCallExpressionArgs;
|
return methodCallExpressionArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string memberName)
|
protected void ResolveNewExpressions(ExpressionParameter parameter, Expression item, string asName)
|
||||||
{
|
{
|
||||||
if (item.NodeType == ExpressionType.Constant)
|
if (item.NodeType == ExpressionType.Constant)
|
||||||
{
|
{
|
||||||
@ -224,23 +224,31 @@ namespace SqlSugar
|
|||||||
this.Start();
|
this.Start();
|
||||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||||
this.Context.ParameterIndex++;
|
this.Context.ParameterIndex++;
|
||||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||||
}
|
}
|
||||||
|
else if ((item is MemberExpression) && ((MemberExpression)item).Expression == null)
|
||||||
|
{
|
||||||
|
var paramterValue= ExpressionTool.GetPropertyValue(item as MemberExpression);
|
||||||
|
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||||
|
this.Context.ParameterIndex++;
|
||||||
|
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||||
|
this.Context.Parameters.Add(new SugarParameter(parameterName, paramterValue));
|
||||||
|
}
|
||||||
else if ((item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
|
else if ((item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant)
|
||||||
{
|
{
|
||||||
this.Expression = item;
|
this.Expression = item;
|
||||||
this.Start();
|
this.Start();
|
||||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||||
this.Context.ParameterIndex++;
|
this.Context.ParameterIndex++;
|
||||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||||
}
|
}
|
||||||
else if (item is MethodCallExpression)
|
else if (item is MethodCallExpression)
|
||||||
{
|
{
|
||||||
this.Expression = item;
|
this.Expression = item;
|
||||||
this.Start();
|
this.Start();
|
||||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
|
||||||
}
|
}
|
||||||
else if (item is MemberExpression)
|
else if (item is MemberExpression)
|
||||||
{
|
{
|
||||||
@ -252,7 +260,7 @@ namespace SqlSugar
|
|||||||
this.Expression = item;
|
this.Expression = item;
|
||||||
this.Start();
|
this.Start();
|
||||||
parameter.IsAppendResult();
|
parameter.IsAppendResult();
|
||||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
|
||||||
this.Context.Result.CurrentParameter = null;
|
this.Context.Result.CurrentParameter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,14 +277,14 @@ namespace SqlSugar
|
|||||||
this.Expression = item;
|
this.Expression = item;
|
||||||
this.Start();
|
this.Start();
|
||||||
parameter.IsAppendResult();
|
parameter.IsAppendResult();
|
||||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
|
||||||
this.Context.Result.CurrentParameter = null;
|
this.Context.Result.CurrentParameter = null;
|
||||||
}
|
}
|
||||||
else if (expression.Expression is ConstantExpression)
|
else if (expression.Expression is ConstantExpression)
|
||||||
{
|
{
|
||||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||||
this.Context.ParameterIndex++;
|
this.Context.ParameterIndex++;
|
||||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||||
this.Context.Parameters.Add(new SugarParameter(parameterName, ExpressionTool.GetMemberValue(expression.Member, expression)));
|
this.Context.Parameters.Add(new SugarParameter(parameterName, ExpressionTool.GetMemberValue(expression.Member, expression)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -287,7 +295,7 @@ namespace SqlSugar
|
|||||||
this.Expression = item;
|
this.Expression = item;
|
||||||
this.Start();
|
this.Start();
|
||||||
parameter.IsAppendResult();
|
parameter.IsAppendResult();
|
||||||
this.Context.Result.Append(this.Context.GetAsString(memberName, parameter.CommonTempData.ObjToString()));
|
this.Context.Result.Append(this.Context.GetAsString(asName, parameter.CommonTempData.ObjToString()));
|
||||||
this.Context.Result.CurrentParameter = null;
|
this.Context.Result.CurrentParameter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,7 +308,7 @@ namespace SqlSugar
|
|||||||
this.Start();
|
this.Start();
|
||||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
string parameterName = this.Context.SqlParameterKeyWord + "constant" + this.Context.ParameterIndex;
|
||||||
this.Context.ParameterIndex++;
|
this.Context.ParameterIndex++;
|
||||||
parameter.Context.Result.Append(this.Context.GetAsString(memberName, parameterName));
|
parameter.Context.Result.Append(this.Context.GetAsString(asName, parameterName));
|
||||||
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
this.Context.Parameters.Add(new SugarParameter(parameterName, parameter.CommonTempData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,7 +325,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
this.Context.Parameters.AddRange(newContext.Parameters);
|
this.Context.Parameters.AddRange(newContext.Parameters);
|
||||||
}
|
}
|
||||||
this.Context.Result.Append(this.Context.GetAsString(memberName, newContext.Result.GetString()));
|
this.Context.Result.Append(this.Context.GetAsString(asName, newContext.Result.GetString()));
|
||||||
this.Context.Result.CurrentParameter = null;
|
this.Context.Result.CurrentParameter = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,9 +337,8 @@ namespace SqlSugar
|
|||||||
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
|
var listProperties = item.Type.GetProperties().Cast<PropertyInfo>().ToList();
|
||||||
foreach (var property in listProperties)
|
foreach (var property in listProperties)
|
||||||
{
|
{
|
||||||
if (this.Context.IgnoreComumnList != null
|
var hasIgnore = this.Context.IgnoreComumnList != null && this.Context.IgnoreComumnList.Any(it => it.EntityName.Equals(item.Type.Name,StringComparison.CurrentCultureIgnoreCase) && it.PropertyName.Equals(property.Name,StringComparison.CurrentCultureIgnoreCase));
|
||||||
&& this.Context.IgnoreComumnList.Any(
|
if (hasIgnore)
|
||||||
it => it.EntityName == item.Type.Name && it.PropertyName == property.Name))
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -341,7 +348,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var asName = this.Context.GetTranslationText(item.Type.Name + "." + property.Name);
|
asName = this.Context.GetTranslationText(item.Type.Name + "." + property.Name);
|
||||||
var columnName = property.Name;
|
var columnName = property.Name;
|
||||||
if (Context.IsJoin)
|
if (Context.IsJoin)
|
||||||
{
|
{
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user