Browse Source

System.HasValue

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
468ac94dfe
  1. 28
      Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Select.cs
  2. 38
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs
  3. BIN
      Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

28
Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Select.cs

@ -24,6 +24,8 @@ namespace OrmTest.UnitTest
single();
single2();
single3();
single4();
single5();
Multiple();
singleDynamic();
MultipleDynamic();
@ -114,6 +116,32 @@ namespace OrmTest.UnitTest
"Select.single3 Error");
}
private void single4(int p = 1)
{
Expression<Func<Student, object>> exp = it => it.CreateTime.HasValue;
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
expContext.IsSingle = false;
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(
@"( [it].[CreateTime]<>'' AND [it].[CreateTime] IS NOT NULL )", null, selectorValue, null,
"Select.single4 Error");
}
private void single5(int p = 1)
{
Expression<Func<Student, object>> exp = it => it.SchoolId.HasValue;
SqlServerExpressionContext expContext = new SqlServerExpressionContext();
expContext.IsSingle = false;
expContext.Resolve(exp, ResolveExpressType.WhereMultiple);
var selectorValue = expContext.Result.GetString();
var pars = expContext.Parameters;
base.Check(
@"( [it].[SchoolId]<>'' AND [it].[SchoolId] IS NOT NULL )", null, selectorValue, null,
"Select.single4 Error");
}
private void singleDynamic()
{
string a = "a";

38
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/UnaryExpressionResolve.cs

@ -34,16 +34,7 @@ namespace SqlSugar
}
else if (isMember)
{
var isComparisonOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue)||baseParameter.OperatorValue.IsNullOrEmpty();
var memberExpression = (base.Expression as MemberExpression);
if (memberExpression.Type== PubConst.BoolType&& isComparisonOperator)
{
Append(parameter, nodeType);
}
else
{
Result(parameter, nodeType);
}
MemberLogic(parameter, baseParameter, nodeType);
}
else if (isConst)
{
@ -59,6 +50,33 @@ namespace SqlSugar
}
}
private void MemberLogic(ExpressionParameter parameter, ExpressionParameter baseParameter, ExpressionType nodeType)
{
var memberExpression = (base.Expression as MemberExpression);
var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty();
var isHasValue = isLogicOperator && memberExpression.Member.Name == "HasValue" && memberExpression.Expression != null && memberExpression.NodeType == ExpressionType.MemberAccess;
if (isHasValue)
{
var member = memberExpression.Expression as MemberExpression;
parameter.CommonTempData = CommonTempDataType.Result;
this.Expression = member;
this.Start();
var result= this.Context.DbMehtods.HasValue(new MethodCallExpressionModel() { Args=new List<MethodCallExpressionArgs>() {
new MethodCallExpressionArgs() { IsMember=true, MemberName= parameter.CommonTempData , MemberValue=null }
} });
this.Context.Result.Append(result);
parameter.CommonTempData = null;
}
else if (memberExpression.Type == PubConst.BoolType && isLogicOperator)
{
Append(parameter, nodeType);
}
else
{
Result(parameter, nodeType);
}
}
private void Result(ExpressionParameter parameter, ExpressionType nodeType)
{
BaseParameter.ChildExpression = base.Expression;

BIN
Src/Asp.Net/SqliteTest/DataBase/SqlSugar4xTest.sqlite

Binary file not shown.
Loading…
Cancel
Save