Browse Source

-

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
001f4d222d
  1. 4
      Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs
  2. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs
  3. 25
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

4
Src/Asp.Net/SqlServerTest/UnitTest/ExpressionTest/Where.cs

@ -400,9 +400,9 @@ namespace OrmTest.UnitTest
expContext.Resolve(exp, ResolveExpressType.WhereSingle); expContext.Resolve(exp, ResolveExpressType.WhereSingle);
var value = expContext.Result.GetString(); var value = expContext.Result.GetString();
var pars = expContext.Parameters; var pars = expContext.Parameters;
base.Check(value, pars, "( CAST( DateName(Year,[Datetime1]) +'-'+ DateName(Month,[Datetime1]) +'-'+ DateName(Day,[Datetime1]) AS DATETIME) > @Date0 )", new List<SugarParameter>() base.Check(value, pars, "( ( [Bool1]=1 ) AND ( [Bool1]=1 ) )", new List<SugarParameter>()
{ {
new SugarParameter("@Date0",DateTime.Now.Date),
}, "whereSingle26"); }, "whereSingle26");
} }

2
Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs

@ -58,7 +58,7 @@ namespace SqlSugar
public static bool IsLogicOperator(string operatorValue) public static bool IsLogicOperator(string operatorValue)
{ {
return operatorValue == "&&" || operatorValue == "||"; return operatorValue == "&&" || operatorValue == "||"||operatorValue == "AND" || operatorValue == "OR";
} }
public static bool IsLogicOperator(Expression expression) public static bool IsLogicOperator(Expression expression)

25
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

@ -21,13 +21,14 @@ namespace SqlSugar
var isBool = expression.Type == UtilConstants.BoolType; var isBool = expression.Type == UtilConstants.BoolType;
var isValueBool = isValue && isBool && parameter.BaseExpression == null; var isValueBool = isValue && isBool && parameter.BaseExpression == null;
var isLength = memberName == "Length" && childIsMember && childExpression.Type == UtilConstants.StringType; var isLength = memberName == "Length" && childIsMember && childExpression.Type == UtilConstants.StringType;
var isDateValue = memberName.IsIn(Enum.GetNames(typeof(DateType))) &&(childIsMember&&childExpression.Type == UtilConstants.DateType); var isDateValue = memberName.IsIn(Enum.GetNames(typeof(DateType))) && (childIsMember && childExpression.Type == UtilConstants.DateType);
var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty(); var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty();
var isHasValue = isLogicOperator && memberName == "HasValue" && expression.Expression != null && expression.NodeType == ExpressionType.MemberAccess; var isHasValue = isLogicOperator && memberName == "HasValue" && expression.Expression != null && expression.NodeType == ExpressionType.MemberAccess;
var isDateDate = memberName == "Date" && expression.Expression.Type == UtilConstants.DateType; var isDateDate = memberName == "Date" && expression.Expression.Type == UtilConstants.DateType;
var isMemberValue = expression.Expression != null && expression.Expression.NodeType != ExpressionType.Parameter && !isValueBool; var isMemberValue = expression.Expression != null && expression.Expression.NodeType != ExpressionType.Parameter && !isValueBool;
var isSingle = parameter.Context.ResolveType == ResolveExpressType.WhereSingle; var isSingle = parameter.Context.ResolveType == ResolveExpressType.WhereSingle;
var fieldIsBool = isBool && isLogicOperator;
baseParameter.ChildExpression = expression;
if (isLength) if (isLength)
{ {
ResolveLength(parameter, isLeft, expression); ResolveLength(parameter, isLeft, expression);
@ -56,9 +57,12 @@ namespace SqlSugar
{ {
ResolveMemberValue(parameter, baseParameter, isLeft, isSetTempData, expression); ResolveMemberValue(parameter, baseParameter, isLeft, isSetTempData, expression);
} }
else if (fieldIsBool)
{
ResolvefieldIsBool(parameter, baseParameter, isLeft, isSetTempData, expression, isSingle);
}
else else
{ {
baseParameter.ChildExpression = expression;
string fieldName = string.Empty; string fieldName = string.Empty;
switch (parameter.Context.ResolveType) switch (parameter.Context.ResolveType)
{ {
@ -165,6 +169,19 @@ namespace SqlSugar
AppendValue(parameter, isLeft, value); AppendValue(parameter, isLeft, value);
} }
} }
private void ResolvefieldIsBool(ExpressionParameter parameter, ExpressionParameter baseParameter, bool? isLeft, bool isSetTempData, MemberExpression expression, bool isSingle)
{
var fieldName = GetName(parameter, expression, isLeft, isSingle);
if (isSetTempData)
{
baseParameter.CommonTempData = fieldName;
}
else
{
fieldName = this.Context.DbMehtods.EqualTrue(fieldName.ObjToString());
AppendMember(parameter, isLeft, fieldName);
}
}
private void ResolveDateDate(ExpressionParameter parameter, bool? isLeft, MemberExpression expression) private void ResolveDateDate(ExpressionParameter parameter, bool? isLeft, MemberExpression expression)
{ {
@ -295,7 +312,7 @@ namespace SqlSugar
string shortName = expression.Expression.ToString(); string shortName = expression.Expression.ToString();
string fieldName = expression.Member.Name; string fieldName = expression.Member.Name;
fieldName = this.Context.GetDbColumnName(expression.Expression.Type.Name, fieldName); fieldName = this.Context.GetDbColumnName(expression.Expression.Type.Name, fieldName);
fieldName = Context.GetTranslationColumnName(shortName +UtilConstants.Dot+ fieldName); fieldName = Context.GetTranslationColumnName(shortName + UtilConstants.Dot + fieldName);
return fieldName; return fieldName;
} }

Loading…
Cancel
Save