protected virtual SqlQuery WhereQuery <T>(Expression <Func <T, bool> > expression) where T : class { var queryProperties = new QueryParameterCollection(); // walk the tree and build up a list of query parameter objects // from the left and right branches of the expression tree ExpressionParserResolver.Resolve(expression.Body).Parser(expression.Body, ExpressionType.Default, ref queryProperties); return(queryProperties.ToQuery()); }
public void Parser(Expression expression, ExpressionType linkingType, ref QueryParameterCollection queryProperties) { var methodCallExpression = (MethodCallExpression)expression; var propertyName = GetPropertyName(methodCallExpression); string propertyValue = MethodCallToSqlArgument(methodCallExpression); var opr = MethodCallToSqlOperand(methodCallExpression); var link = GetLinkOperator(linkingType); if (!string.IsNullOrEmpty(propertyName) && !string.IsNullOrEmpty(propertyValue) && !string.IsNullOrEmpty(opr)) { queryProperties.Add(new QueryParameter(link, propertyName, propertyValue, opr)); } }
public void Parser(Expression expression, ExpressionType linkingType, ref QueryParameterCollection queryProperties) { var binary = (BinaryExpression)expression; if (expression.NodeType != ExpressionType.AndAlso && expression.NodeType != ExpressionType.OrElse) { var propertyName = GetPropertyName(binary); dynamic propertyValue = GetPropetyValue(binary.Right as MemberExpression); var opr = GetOperator(expression.NodeType); var link = GetLinkOperator(linkingType); queryProperties.Add(new QueryParameter(link, propertyName, propertyValue, opr)); } else { Resolver.Resolve(binary.Left).Parser(binary.Left, expression.NodeType, ref queryProperties); Resolver.Resolve(binary.Right).Parser(binary.Right, expression.NodeType, ref queryProperties); } }