Exemplo n.º 1
0
 public TableExpression(TableAlias alias, string name)
     : base(DbExpressionType.Table, typeof(void), alias)
 {
     this.name = name;
 }
Exemplo n.º 2
0
        public static SelectExpression AddRedundantSelect(this SelectExpression select, TableAlias newAlias)
        {
            var newColumns = select.Columns.Select(d => new ColumnDeclaration(d.Name, new ColumnExpression(d.Expression.Type, newAlias, d.Name)));
            var newFrom    = new SelectExpression(newAlias, select.Columns, select.From, select.Where, select.OrderBy, select.GroupBy, select.IsDistinct, select.Skip, select.Take);

            return(new SelectExpression(select.Alias, newColumns, newFrom, null, null, null, false, null, null));
        }
Exemplo n.º 3
0
 protected AliasedExpression(DbExpressionType nodeType, Type type, TableAlias alias)
     : base(nodeType, type)
 {
     this.alias = alias;
 }
Exemplo n.º 4
0
 public ColumnExpression(Type type, TableAlias alias, string name)
     : base(DbExpressionType.Column, type)
 {
     this.alias = alias;
     this.name  = name;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Get an expression for a mapped property relative to a root expression.
        /// The root is either a TableExpression or an expression defining an entity instance.
        /// </summary>
        /// <param name="root"></param>
        /// <param name="member"></param>
        /// <returns></returns>
        public virtual Expression GetMemberExpression(Expression root, MemberInfo member)
        {
            if (IsRelationship(member))
            {
                Type rowType = GetRelatedType(member);
                ProjectionExpression projection = GetTableQuery(rowType);

                // make where clause for joining back to 'root'
                List <MemberInfo> declaredTypeMembers;
                List <MemberInfo> associatedMembers;
                GetAssociationKeys(member, out declaredTypeMembers, out associatedMembers);

                Expression where = null;
                for (int i = 0, n = associatedMembers.Count; i < n; i++)
                {
                    Expression equal = Expression.Equal(
                        GetMemberExpression(projection.Projector, associatedMembers[i]),
                        GetMemberExpression(root, declaredTypeMembers[i])
                        );
                    where = (where != null) ? Expression.And(where, equal) : equal;
                }

                TableAlias newAlias = new TableAlias();
                var        pc       = ColumnProjector.ProjectColumns(this.Language.CanBeColumn,
                                                                     projection.Projector,
                                                                     null,
                                                                     newAlias,
                                                                     projection.Source.Alias);

                LambdaExpression aggregator = GetAggregator(TypeHelper.GetMemberType(member),
                                                            typeof(IEnumerable <>).MakeGenericType(
                                                                pc.Projector.Type));
                return(new ProjectionExpression(
                           new SelectExpression(newAlias, pc.Columns, projection.Source, where),
                           pc.Projector,
                           aggregator
                           ));
            }
            var tableExpression = root as TableExpression;

            if (tableExpression != null)
            {
                if (IsColumn(member))
                {
                    IColumn column = null;
                    if (tableExpression.Table != null)
                    {
                        column = tableExpression.Table.GetColumnByPropertyName(member.Name);
                    }
                    var columnName = column != null?GetColumnName(column) : GetColumnName(member);

                    return(!string.IsNullOrEmpty(columnName)
                               ? new ColumnExpression(column,
                                                      TypeHelper.GetMemberType(member),
                                                      tableExpression.Alias,
                                                      columnName)
                               : root);
                }
                return(this.GetTypeProjection(root, TypeHelper.GetMemberType(member)));
            }
            return(QueryBinder.BindMember(root, member));
        }
Exemplo n.º 6
0
 public TableExpression(ITable table, TableAlias alias, string name) : this(alias, name)
 {
     _table = table;
 }
Exemplo n.º 7
0
 public ColumnExpression(IColumn column, Type type, TableAlias alias, string name)
     : this(type, alias, name)
 {
     _column = column;
 }