public SubQueryColumn(QuerySource.SubQuery querySource, QueryField field) { QuerySource = querySource; Field = field; ParsingTracer.WriteLine(field); }
public override FieldIndex[] Select <T>(ExpressionParser <T> parser) { ParsingTracer.WriteLine(this); ParsingTracer.WriteLine(QuerySource); ParsingTracer.IncIndentLevel(); if (_index == null) { SetSubIndex(parser); _index = new FieldIndex[_subIndex.Length]; for (var i = 0; i < _subIndex.Length; i++) { var col = QuerySource.SubSql.Select.Columns[_subIndex[i].Index]; _index[i] = new FieldIndex { Index = QuerySource.SqlQuery.Select.Add(col), Field = this }; } } ParsingTracer.DecIndentLevel(); ParsingTracer.WriteLine(QuerySource); return(_index); }
public Expr(SqlQuery sqlBilder, LambdaInfo lambda, params QuerySource[] baseQueries) : base(sqlBilder, lambda, baseQueries) { if (lambda.Body is NewExpression) { var ex = (NewExpression)lambda.Body; if (ex.Members == null) { return; } for (var i = 0; i < ex.Members.Count; i++) { var member = ex.Members[i]; if (member is MethodInfo) { member = TypeHelper.GetPropertyByMethod((MethodInfo)member); } var field = GetBaseField(lambda, ex.Arguments[i]) ?? new ExprColumn(this, ex.Arguments[i], member.Name); Fields.Add(field); Members.Add(member, field); } } else if (lambda.Body is MemberInitExpression) { var ex = (MemberInitExpression)lambda.Body; for (var i = 0; i < ex.Bindings.Count; i++) { var binding = ex.Bindings[i]; var member = binding.Member; if (member is MethodInfo) { member = TypeHelper.GetPropertyByMethod((MethodInfo)member); } if (binding is MemberAssignment) { var ma = binding as MemberAssignment; var field = GetBaseField(lambda, ma.Expression) ?? new ExprColumn(this, ma.Expression, member.Name); Fields.Add(field); Members.Add(member, field); } else { throw new InvalidOperationException(); } } } ParsingTracer.DecIndentLevel(); }
public override FieldIndex[] Select <T>(ExpressionParser <T> parser) { ParsingTracer.WriteLine(this); ParsingTracer.IncIndentLevel(); if (_indexes == null) { var indexes = new List <FieldIndex>(Fields.Count); foreach (var field in Fields) { foreach (var idx in field.Select(parser)) { indexes.Add(new FieldIndex { Index = idx.Index, Field = field }); } } _indexes = indexes.ToArray(); } ParsingTracer.DecIndentLevel(); return(_indexes); }
public GroupBy( SqlQuery sqlQuery, QuerySource groupQuery, QuerySource originalQuery, LambdaInfo keySelector, QuerySource elementSource, Type groupingType, bool isWrapped, ISqlExpression[] byExpressions) : base(sqlQuery, keySelector, groupQuery) { ParsingTracer.IncIndentLevel(); OriginalQuery = originalQuery; ElementSource = elementSource; GroupingType = groupingType; IsWrapped = isWrapped; ByExpressions = byExpressions; var field = new GroupByColumn(this); Fields.Add(field); Members.Add(groupingType.GetProperty("Key"), field); ParsingTracer.DecIndentLevel(); }
public ExprColumn(QuerySource source, Expression expr, string alias) { QuerySource = source; Expr = expr; _alias = alias; ParsingTracer.WriteLine(this); }
public SubQuerySourceColumn(SubQuery querySource, QuerySource sourceColumn) : base(sourceColumn.SqlQuery, sourceColumn.Lambda, sourceColumn.Sources) { QuerySource = querySource; SourceColumn = sourceColumn; ParsingTracer.WriteLine(sourceColumn); }
public Column(QuerySource.Table table, SqlField field, MemberMapper mapper) { Field = field; Table = table; Mapper = mapper; ParsingTracer.WriteLine(this); }
public ExprColumn(QuerySource source, ISqlExpression expr, string alias) { QuerySource = source; _sqlExpression = expr; _alias = alias; ParsingTracer.WriteLine("sql", this); }
public Scalar(SqlQuery sqlBilder, LambdaInfo lambda, ISqlExpression field, params QuerySource[] baseQueries) : base(sqlBilder, lambda, baseQueries) { _field = new ExprColumn(this, field, null); Fields.Add(_field); ParsingTracer.DecIndentLevel(); }
public Scalar(SqlQuery sqlBilder, LambdaInfo lambda, params QuerySource[] baseQueries) : base(sqlBilder, lambda, baseQueries) { _field = GetBaseField(lambda, lambda.Body) ?? new ExprColumn(this, lambda.Body, null); Fields.Add(_field); ParsingTracer.DecIndentLevel(); }
public Table(MappingSchema mappingSchema, SqlQuery sqlQuery, Type type) : base(sqlQuery, null) { OriginalType = type; _objectType = GetObjectType(OriginalType, mappingSchema); SqlTable = new SqlTable(mappingSchema, _objectType); sqlQuery.From.Table(SqlTable); Init(mappingSchema); ParsingTracer.DecIndentLevel(); }
public override FieldIndex[] Select <T>(ExpressionParser <T> _) { ParsingTracer.WriteLine(this); ParsingTracer.WriteLine("table", Table); ParsingTracer.IncIndentLevel(); var index = new[] { new FieldIndex { Index = Table.SqlQuery.Select.Add(Field, Field.Alias), Field = this } }; ParsingTracer.DecIndentLevel(); ParsingTracer.WriteLine("table", Table); return(index); }
public override FieldIndex[] Select <T>(ExpressionParser <T> parser) { ParsingTracer.WriteLine(this); ParsingTracer.WriteLine(GroupBySource.BaseQuery); ParsingTracer.IncIndentLevel(); if (_index == null) { _index = GroupBySource.BaseQuery.Select(parser); } ParsingTracer.DecIndentLevel(); ParsingTracer.WriteLine(GroupBySource.BaseQuery); return(_index); }
public Table(MappingSchema mappingSchema, SqlQuery sqlQuery, LambdaInfo lambda) : base(sqlQuery, lambda) { var type = TypeHelper.GetGenericType(typeof(IEnumerable <>), lambda.Body.Type); OriginalType = type == null ? lambda.Body.Type : type.GetGenericArguments()[0]; _objectType = GetObjectType(OriginalType, mappingSchema); SqlTable = new SqlTable(mappingSchema, _objectType); sqlQuery.From.Table(SqlTable); Init(mappingSchema); ParsingTracer.DecIndentLevel(); }
Table(MappingSchema mappingSchema, SqlQuery sqlQuery, Association association, Table parent) : base(sqlQuery, null) { var type = TypeHelper.GetMemberType(association.MemberAccessor.MemberInfo); var left = association.CanBeNull; var isList = false; if (TypeHelper.IsSameOrParent(typeof(IEnumerable), type)) { var etypes = TypeHelper.GetGenericArguments(type, typeof(IEnumerable)); type = etypes != null && etypes.Length > 0 ? etypes[0] : TypeHelper.GetListItemType(type); isList = true; } OriginalType = type; _objectType = GetObjectType(OriginalType, mappingSchema); SqlTable = new SqlTable(mappingSchema, ObjectType); var psrc = sqlQuery.From[parent.SqlTable]; var join = left ? SqlTable.WeakLeftJoin() : isList?SqlTable.InnerJoin() : SqlTable.WeakInnerJoin(); _parentAssociation = parent; _parentAssociationJoin = join.JoinedTable; psrc.Joins.Add(join.JoinedTable); Init(mappingSchema); for (var i = 0; i < association.ThisKey.Length; i++) { Column col1, col2; if (!parent._columns.TryGetValue(association.ThisKey[i], out col1)) { throw new LinqException("Association key '{0}' not found for type '{1}.", association.ThisKey[i], parent.ObjectType); } if (!_columns.TryGetValue(association.OtherKey[i], out col2)) { throw new LinqException("Association key '{0}' not found for type '{1}.", association.OtherKey[i], ObjectType); } join.Field(col1.Field).Equal.Field(col2.Field); } ParsingTracer.DecIndentLevel(); }
public SubQuery(SqlQuery currentSql, SqlQuery subSql, QuerySource baseQuery, bool addToSource) : base(currentSql, baseQuery.Lambda, baseQuery) { ParsingTracer.WriteLine(subSql); SubSql = subSql; if (addToSource) { SqlQuery.From.Table(subSql); } foreach (var field in baseQuery.Fields) { EnsureField(field); } ParsingTracer.DecIndentLevel(); }
public override FieldIndex[] Select <T>(ExpressionParser <T> parser) { ParsingTracer.WriteLine(this); ParsingTracer.WriteLine(QuerySource); ParsingTracer.IncIndentLevel(); if (_index == null) { if (_sqlExpression == null) { _sqlExpression = Parse(parser, QuerySource.Sources); } _index = new[] { new FieldIndex { Index = QuerySource.SqlQuery.Select.Add(_sqlExpression, _alias), Field = this } }; } ParsingTracer.DecIndentLevel(); ParsingTracer.WriteLine(QuerySource); return(_index); }
protected QuerySource(SqlQuery sqlQuery, LambdaInfo lambda, params QuerySource[] baseQueries) { SqlQuery = sqlQuery; Lambda = lambda; _sources = baseQueries; #if DEBUG && TRACE_PARSING ParsingTracer.WriteLine(lambda); ParsingTracer.WriteLine(this); foreach (var query in baseQueries) { ParsingTracer.WriteLine("base", query); } foreach (var field in Fields) { ParsingTracer.WriteLine("field ", field); } ParsingTracer.IncIndentLevel(); #endif }
public GroupByColumn(QuerySource.GroupBy groupBySource) { GroupBySource = groupBySource; ParsingTracer.WriteLine("groupBy", this); }