Browse Source

Update Expression To Sql

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
6f3dd0528e
  1. 2
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 23
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

2
Src/Asp.Net/SqlServerTest/Demos/1_Query.cs

@ -446,7 +446,7 @@ namespace OrmTest.Demo
x =p
}).ToList();
var test46 = db.Queryable<Student>().Where(it => it.CreateTime > SqlFunc.ToDate(DateTime.Now.Date)).ToList();
//var test47 = db.Queryable<Student>().Where(it =>string.IsNullOrEmpty(it.Name)==true).ToList();
var test47 = db.Queryable<Student>().Where(it =>string.IsNullOrEmpty(it.Name)==true).ToList();
}
public static void Page()
{

23
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs

@ -249,12 +249,13 @@ namespace SqlSugar
model.Args.AddRange(appendArgs);
}
var methodValue = GetMethodValue(name, model);
if (parameter.BaseExpression is BinaryExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType&&name=="HasValue"&&!(parameter.OppsiteExpression is BinaryExpression)&& !(parameter.OppsiteExpression is MethodCallExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType)) {
methodValue = this.Context.DbMehtods.CaseWhen(new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("IF",methodValue.ObjToString()),
new KeyValuePair<string, string>("Return","1"),
new KeyValuePair<string, string>("End","0")
});
if (parameter.BaseExpression is BinaryExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType&&name=="HasValue"&&!(parameter.OppsiteExpression is BinaryExpression)&& !(parameter.OppsiteExpression is MethodCallExpression && parameter.OppsiteExpression.Type == UtilConstants.BoolType))
{
methodValue = packIfElse(methodValue);
}
if (parameter.OppsiteExpression != null&&name == "IsNullOrEmpty" && parameter.OppsiteExpression.Type == UtilConstants.BoolType&& parameter.OppsiteExpression is ConstantExpression)
{
methodValue = packIfElse(methodValue);
}
var isRoot = contextIndex == 2;
if (isRoot && parameter.BaseExpression == null &&this.Context.ResolveType.IsIn(ResolveExpressType.WhereMultiple,ResolveExpressType.WhereSingle)&& (parameter.CurrentExpression is MethodCallExpression) && ((parameter.CurrentExpression as MethodCallExpression).Method.Name.IsIn("ToBool", "ToBoolean")))
@ -284,6 +285,16 @@ namespace SqlSugar
base.AppendValue(parameter, isLeft, methodValue);
}
private object packIfElse(object methodValue)
{
methodValue = this.Context.DbMehtods.CaseWhen(new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("IF",methodValue.ObjToString()),
new KeyValuePair<string, string>("Return","1"),
new KeyValuePair<string, string>("End","0")
});
return methodValue;
}
private void AppendItem(ExpressionParameter parameter, string name, IEnumerable<Expression> args, MethodCallExpressionModel model, Expression item)
{
var isBinaryExpression = item is BinaryExpression || item is MethodCallExpression;

Loading…
Cancel
Save