Browse Source

-

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
c6b47f4caf
  1. 14
      Src/Asp.Net/SqlServerTest/Demos/1_Query.cs
  2. 8
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MemberExpressionResolve.cs

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

@ -284,12 +284,14 @@ namespace OrmTest.Demo
var getUnionAllList2 = db.UnionAll(db.Queryable<Student>(), db.Queryable<Student>()).ToList();
var test1 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Where(st=>st.CreateTime>SqlFunc.GetDate()).Select((st, sc) => SqlFunc.ToInt64(sc.Id)).ToList();
//var test2 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id)
// .Where(st =>
// SqlFunc.IF(st.Id > 1)
// .Return(st.Id)
// .ElseIF(st.Id == 1)
// .Return(st.SchoolId).End(st.Id) == 1).ToList();
var test2 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id)
.Where(st =>
SqlFunc.IF(st.Id > 1)
.Return(st.Id)
.ElseIF(st.Id == 1)
.Return(st.SchoolId).End(st.Id) == 1).ToList();
var test3 = db.Queryable<DataTestInfo2>().Select(it => it.Bool1).ToSql();
var test4 = db.Queryable<DataTestInfo2>().Select(it => new { b=it.Bool1 }).ToSql();
}
public static void Page()
{

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

@ -15,11 +15,12 @@ namespace SqlSugar
var childExpression = expression.Expression as MemberExpression;
var memberName = expression.Member.Name;
var childIsMember = childExpression != null;
var isRoot = parameter.BaseExpression == null;
var isLeft = parameter.IsLeft;
var isSetTempData = parameter.IsSetTempData;
var isValue = memberName == "Value" && expression.Member.DeclaringType.Name == "Nullable`1";
var isBool = expression.Type == UtilConstants.BoolType;
var isValueBool = isValue && isBool && parameter.BaseExpression == null;
var isValueBool = isValue && isBool && isRoot;
var isLength = memberName == "Length" && childIsMember && childExpression.Type == UtilConstants.StringType;
var isDateValue = memberName.IsIn(Enum.GetNames(typeof(DateType))) && (childIsMember && childExpression.Type == UtilConstants.DateType);
var isLogicOperator = ExpressionTool.IsLogicOperator(baseParameter.OperatorValue) || baseParameter.OperatorValue.IsNullOrEmpty();
@ -28,6 +29,9 @@ namespace SqlSugar
var isMemberValue = expression.Expression != null && expression.Expression.NodeType != ExpressionType.Parameter && !isValueBool;
var isSingle = parameter.Context.ResolveType == ResolveExpressType.WhereSingle;
var fieldIsBool = isBool && isLogicOperator&&(parameter.BaseParameter==null||!(parameter.BaseParameter.CurrentExpression is MemberInitExpression|| parameter.BaseParameter.CurrentExpression is NewExpression));
var isSelect = this.Context.ResolveType.IsIn(ResolveExpressType.SelectSingle, ResolveExpressType.SelectMultiple);
var isSelectField = isSelect && isRoot;
var isField = this.Context.ResolveType.IsIn(ResolveExpressType.FieldSingle, ResolveExpressType.FieldMultiple);
baseParameter.ChildExpression = expression;
if (isLength)
{
@ -57,7 +61,7 @@ namespace SqlSugar
{
ResolveMemberValue(parameter, baseParameter, isLeft, isSetTempData, expression);
}
else if (fieldIsBool&& !this.Context.ResolveType.IsIn(ResolveExpressType.FieldSingle, ResolveExpressType.FieldMultiple))
else if (fieldIsBool&& !isField&&!isSelectField)
{
ResolvefieldIsBool(parameter, baseParameter, isLeft, isSetTempData, expression, isSingle);
}

Loading…
Cancel
Save