static void AppendLimitCondition(DbSqlQueryExpression sqlQuery, int limitCount) { DbLessThanExpression lessThanExp = DbExpression.LessThan(OracleSemantics.DbMemberExpression_ROWNUM, DbExpression.Constant(limitCount + 1)); DbExpression condition = lessThanExp; if (sqlQuery.Condition != null) { condition = DbExpression.And(sqlQuery.Condition, condition); } sqlQuery.Condition = condition; }
protected override Expression VisitBinary(BinaryExpression node) { var expression = base.VisitBinary(node) as BinaryExpression; DbExpression dbExpression; // Need special handling for comparisons against the null constant. If we don't translate these // using an "IsNull" expression, EF will convert it literally as "= null" which doesn't work in SQL Server. if (IsNullConstantExpression(expression.Right)) { dbExpression = MapNullComparison(expression.Left, expression.NodeType); } else if (IsNullConstantExpression(expression.Left)) { dbExpression = MapNullComparison(expression.Right, expression.NodeType); } else { DbExpression leftExpression = GetDbExpressionForExpression(expression.Left); DbExpression rightExpression = GetDbExpressionForExpression(expression.Right); switch (expression.NodeType) { case ExpressionType.Equal: // DbPropertyExpression = class property that has been mapped to a database column // DbParameterReferenceExpression = lambda parameter if (IsNullableExpressionOfType <DbPropertyExpression>(leftExpression) && IsNullableExpressionOfType <DbParameterReferenceExpression>(rightExpression)) { dbExpression = CreateEqualComparisonOfNullablePropToNullableParam(leftExpression, rightExpression); } else if (IsNullableExpressionOfType <DbPropertyExpression>(rightExpression) && IsNullableExpressionOfType <DbParameterReferenceExpression>(leftExpression)) { dbExpression = CreateEqualComparisonOfNullablePropToNullableParam(rightExpression, leftExpression); } else { dbExpression = leftExpression.Equal(rightExpression); } break; case ExpressionType.NotEqual: dbExpression = leftExpression.NotEqual(rightExpression); break; case ExpressionType.GreaterThan: dbExpression = leftExpression.GreaterThan(rightExpression); break; case ExpressionType.GreaterThanOrEqual: dbExpression = leftExpression.GreaterThanOrEqual(rightExpression); break; case ExpressionType.LessThan: dbExpression = leftExpression.LessThan(rightExpression); break; case ExpressionType.LessThanOrEqual: dbExpression = leftExpression.LessThanOrEqual(rightExpression); break; case ExpressionType.AndAlso: dbExpression = leftExpression.And(rightExpression); break; case ExpressionType.OrElse: dbExpression = leftExpression.Or(rightExpression); break; default: throw new NotImplementedException(string.Format("Unhandled NodeType of {0} in LambdaToDbExpressionVisitor.VisitBinary", expression.NodeType)); } } MapExpressionToDbExpression(expression, dbExpression); return(expression); }