private static AbstractSqlCondition ParseBinaryExpression(AbstractSqlCommandWithWhere sourceCommand, BinaryExpression expr) { switch (expr.NodeType) { case ExpressionType.Equal: return(ParseBinaryExpression(sourceCommand, expr, SqlOperator.Equal)); case ExpressionType.NotEqual: return(ParseBinaryExpression(sourceCommand, expr, SqlOperator.NotEqual)); case ExpressionType.GreaterThan: return(ParseBinaryExpression(sourceCommand, expr, SqlOperator.GreaterThan)); case ExpressionType.LessThan: return(ParseBinaryExpression(sourceCommand, expr, SqlOperator.LessThan)); case ExpressionType.GreaterThanOrEqual: return(ParseBinaryExpression(sourceCommand, expr, SqlOperator.GreaterThanOrEqual)); case ExpressionType.LessThanOrEqual: return(ParseBinaryExpression(sourceCommand, expr, SqlOperator.LessThanOrEqual)); case ExpressionType.And: case ExpressionType.AndAlso: return(SqlLinqCondition.ParseCondition(sourceCommand, expr.Left) & SqlLinqCondition.ParseCondition(sourceCommand, expr.Right)); case ExpressionType.Or: case ExpressionType.OrElse: return(SqlLinqCondition.ParseCondition(sourceCommand, expr.Left) | SqlLinqCondition.ParseCondition(sourceCommand, expr.Right)); default: throw new LinqNotSupportedException("Not supported this linq operation!"); } }
/// <summary> /// 创建新的Sql条件语句 /// </summary> /// <typeparam name="T">实体类类型</typeparam> /// <param name="sourceCommand">来源语句</param> /// <param name="expr">Linq表达式</param> /// <exception cref="LinqNotSupportedException">Linq操作不支持</exception> /// <exception cref="NullAttributeException">没有设置特性</exception> /// <returns>Sql条件语句</returns> public static AbstractSqlCondition Create <T>(AbstractSqlCommandWithWhere sourceCommand, Expression <Func <T, Boolean> > expr) { return(SqlLinqCondition.ParseCondition(sourceCommand, expr.Body)); }