mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
-
This commit is contained in:
parent
a99c807ff8
commit
eedb57ae6c
Binary file not shown.
@ -14,27 +14,29 @@ namespace OrmTest.ExpressionTest
|
||||
internal static void Init()
|
||||
{
|
||||
|
||||
o1();
|
||||
o2();
|
||||
single();
|
||||
singleDynamic();
|
||||
}
|
||||
|
||||
private static void o1()
|
||||
private static void single()
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id=it.Id };
|
||||
int p = 1;
|
||||
Expression<Func<Student, object>> exp = it => new Student() { Name = "a", Id=it.Id, SchoolId=p };
|
||||
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
|
||||
expContext.ResolveType = ResolveExpressType.SelectSingle;
|
||||
expContext.Resolve();
|
||||
var x = expContext.Result.GetString();
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
}
|
||||
|
||||
private static void o2()
|
||||
private static void singleDynamic()
|
||||
{
|
||||
Expression<Func<Student, object>> exp = it =>new { x = "a" };
|
||||
string a = "a";
|
||||
Expression<Func<Student, object>> exp = it =>new { x = it.Id, shoolid=1,name=a };
|
||||
ExpressionContext expContext = new ExpressionContext(exp, ResolveExpressType.WhereSingle);
|
||||
expContext.ResolveType = ResolveExpressType.SelectSingle;
|
||||
expContext.Resolve();
|
||||
var x = expContext.Result.GetString();
|
||||
var selectorValue = expContext.Result.GetString();
|
||||
var pars = expContext.Parameters;
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -177,5 +177,15 @@ namespace SqlSugar
|
||||
return ((FieldInfo)propertyOrField).FieldType;
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public static bool IsEntity(Type type)
|
||||
{
|
||||
return type.IsClass && type!=ExpressionConst.StringType;
|
||||
}
|
||||
|
||||
public static bool IsValueType(Type type)
|
||||
{
|
||||
return !IsEntity(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,33 +43,30 @@ namespace SqlSugar
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
MemberAssignment memberAssignment = (MemberAssignment)binding;
|
||||
MemberInfo member = memberAssignment.Member;
|
||||
Type memberType = ExpressionTool.GetPropertyOrFieldType(member);
|
||||
var name = memberType.Name;
|
||||
var isValueType = memberType.IsValueType || memberType == ExpressionConst.StringType;
|
||||
if (isValueType)
|
||||
if (memberAssignment.Expression.NodeType == ExpressionType.Constant)
|
||||
{
|
||||
if (memberAssignment.Expression.NodeType==ExpressionType.Constant)
|
||||
var value = ((ConstantExpression)memberAssignment.Expression).Value;
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
||||
parameter.Context.Result.Append(parameterName);
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
var memberExpression = (MemberExpression)memberAssignment.Expression;
|
||||
if (memberExpression.Expression.NodeType.IsIn(ExpressionType.Constant))
|
||||
{
|
||||
var value= ((ConstantExpression)memberAssignment.Expression).Value;
|
||||
var value = ExpressionTool.GetMemberValue(memberExpression.Member, memberExpression);
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
||||
parameter.Context.Result.Append(parameterName);
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
var memberExpression = (MemberExpression)memberAssignment.Expression;
|
||||
var fieldNme = (memberExpression).Member.Name;
|
||||
parameter.Context.Result.Append(fieldNme);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,18 @@ namespace SqlSugar
|
||||
}
|
||||
else
|
||||
{
|
||||
var memberExpression = (MemberExpression)Expression;
|
||||
var fieldNme = (memberExpression).Member.Name;
|
||||
parameter.Context.Result.Append(fieldNme);
|
||||
var memberExpression = (MemberExpression)item;
|
||||
if (memberExpression.Expression.NodeType.IsIn(ExpressionType.Constant))
|
||||
{
|
||||
var value =ExpressionTool.GetMemberValue(memberExpression.Member, memberExpression);
|
||||
string parameterName = this.Context.SqlParameterKeyWord + "constant" + i;
|
||||
parameter.Context.Result.Append(parameterName);
|
||||
this.Context.Parameters.Add(new SugarParameter(parameterName, value));
|
||||
}
|
||||
else {
|
||||
var fieldNme = (memberExpression).Member.Name;
|
||||
parameter.Context.Result.Append(fieldNme);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user