private static void HandleDuplicates(Select select, MethodCallExpression expression) { if (select.Duplicates == null) { select.Duplicates = new Duplicates(); } select.Duplicates.Distinct = ProjectionVisitor <T> .CreateModel(expression.ArgumentAt(2)); if (expression.Arguments.Count == 2) { select.Duplicates.OrderBy.Add(new OrderBy { Type = OrderBy.SourceType.Projection, Projection = select.Duplicates.Distinct, Order = Order.Ascending }); } else { Enumerable.Range(3, expression.Arguments.Count - 2) .Where(x => x % 2 == 1) .Select(x => new { Index = x, IsProjection = ProjectionVisitor <T> .IsProjection(expression.ArgumentAt(x).GetLambdaBody()) }) .ToList().ForEach(x => select.Duplicates.OrderBy.Add(new OrderBy { Type = x.IsProjection ? OrderBy.SourceType.Projection : OrderBy.SourceType.Operator, Projection = x.IsProjection ? ProjectionVisitor <T> .CreateModel(expression.ArgumentAt(x.Index)) : null, Operator = !x.IsProjection ? WhereVisitor <T> .CreateModel(expression.ArgumentAt(x.Index), select.From.Alias) : null, Order = expression.ConstantArgumentAt <Order>(x.Index + 1) })); } }
public static Operator CreateModel(Expression expression, string tableAlias = null) { var visitor = new WhereVisitor <T>(tableAlias); Operator where = null; visitor.Visit(expression, x => where = x.Operator); return(where); }
private static void HandleWhere(Select select, MethodCallExpression expression) { var where = WhereVisitor <T> .CreateModel(expression.ArgumentAt(2), select.From.Alias); if (!select.HasWhere) { select.Where = where; } else { var @operator = Operator.Create.ByType(Operator.OperatorType.And); @operator.LeftOperand = Operand.Create.Operator(select.Where); @operator.RightOperand = Operand.Create.Operator(where); select.Where = @operator; } }