コード例 #1
0
ファイル: Translator.cs プロジェクト: X10sions/X10sions
        internal SqlNode TranslateLink(SqlLink link, List <SqlExpression> keyExpressions, bool asExpression)
        {
            var member = link.Member;

            if (member.IsAssociation)
            {
                var        otherType   = member.Association.OtherType;
                var        type        = otherType.InheritanceRoot.Type;
                var        table       = services.Context.GetTable(type);
                Expression otherSource = new LinkedTableExpression(link, table, typeof(IQueryable <>).MakeGenericType(otherType.Type));
                var        array       = new Expression[keyExpressions.Count];
                for (var i = 0; i < keyExpressions.Count; i++)
                {
                    var metaDataMember = member.Association.OtherKey[i];
                    var memberType     = TypeSystem.GetMemberType(metaDataMember.Member);
                    array[i] = InternalExpression.Known(keyExpressions[i], memberType);
                }
                var     thisInstance   = (link.Expression != null) ? ((Expression)InternalExpression.Known(link.Expression)) : ((Expression)Expression.Constant(null, link.Member.Member.DeclaringType));
                var     node           = TranslateAssociation(services.Context, member.Association, otherSource, array, thisInstance);
                var     queryConverter = new QueryConverter(services, typeProvider, this, sql);
                var     sqlSelect      = (SqlSelect)queryConverter.ConvertInner(node, link.SourceExpression);
                SqlNode result         = sqlSelect;
                if (asExpression)
                {
                    result = ((!member.Association.IsMany) ? new SqlSubSelect(SqlNodeType.Element, link.ClrType, link.SqlType, sqlSelect) : new SqlSubSelect(SqlNodeType.Multiset, link.ClrType, link.SqlType, sqlSelect));
                }
                return(result);
            }
            return(link.Expansion);
        }
コード例 #2
0
        internal SqlNode TranslateLink(SqlLink link, List <SqlExpression> keyExpressions, bool asExpression)
        {
            MetaDataMember mm = link.Member;

            if (mm.IsAssociation)
            {
                // Create the row source.
                MetaType   otherType = mm.Association.OtherType;
                Type       tableType = otherType.InheritanceRoot.Type;
                ITable     table     = this.services.Context.GetTable(tableType);
                Expression source    = new LinkedTableExpression(link, table, typeof(IQueryable <>).MakeGenericType(otherType.Type));
                // Build key expression nodes.
                Expression[] keyExprs = new Expression[keyExpressions.Count];
                for (int i = 0; i < keyExpressions.Count; ++i)
                {
                    MetaDataMember metaMember = mm.Association.OtherKey[i];
                    Type           memberType = TypeSystem.GetMemberType(metaMember.Member);
                    keyExprs[i] = InternalExpression.Known(keyExpressions[i], memberType);
                }
                Expression lex = link.Expression != null
                    ? (Expression)InternalExpression.Known(link.Expression)
                    : (Expression)Expression.Constant(null, link.Member.Member.DeclaringType);
                Expression expr = TranslateAssociation(this.services.Context, mm.Association, source, keyExprs, lex);
                // Convert
                QueryConverter qc  = new QueryConverter(this.services, this.typeProvider, this, this.sql);
                SqlSelect      sel = (SqlSelect)qc.ConvertInner(expr, link.SourceExpression);
                // Turn it into an expression is necessary
                SqlNode result = sel;
                if (asExpression)
                {
                    if (mm.Association.IsMany)
                    {
                        result = new SqlSubSelect(SqlNodeType.Multiset, link.ClrType, link.SqlType, sel);
                    }
                    else
                    {
                        result = new SqlSubSelect(SqlNodeType.Element, link.ClrType, link.SqlType, sel);
                    }
                }
                return(result);
            }
            else
            {
                System.Diagnostics.Debug.Assert(link.Expansion != null);
                System.Diagnostics.Debug.Assert(link.KeyExpressions == keyExpressions);
                // deferred expression already defined...
                return(link.Expansion);
            }
        }
コード例 #3
0
ファイル: QueryConverter.cs プロジェクト: uQr/referencesource
 private SqlNode VisitLinkedTable(LinkedTableExpression linkedTable) {
     return TranslateConstantTable(linkedTable.Table, linkedTable.Link);
 }
コード例 #4
0
        internal SqlNode TranslateLink(SqlLink link, List<SqlExpression> keyExpressions, bool asExpression) {
            MetaDataMember mm = link.Member;

            if (mm.IsAssociation) {
                // Create the row source.
                MetaType otherType = mm.Association.OtherType;
                Type tableType = otherType.InheritanceRoot.Type;
                ITable table = this.services.Context.GetTable(tableType);
                Expression source = new LinkedTableExpression(link, table, typeof(IQueryable<>).MakeGenericType(otherType.Type));
                // Build key expression nodes.
                Expression[] keyExprs = new Expression[keyExpressions.Count];
                for (int i = 0; i < keyExpressions.Count; ++i) {
                    MetaDataMember metaMember = mm.Association.OtherKey[i];
                    Type memberType = TypeSystem.GetMemberType(metaMember.Member);
                    keyExprs[i] = InternalExpression.Known(keyExpressions[i], memberType);
                }
                Expression lex = link.Expression != null 
                    ? (Expression)InternalExpression.Known(link.Expression) 
                    : (Expression)Expression.Constant(null, link.Member.Member.DeclaringType);
                Expression expr = TranslateAssociation(this.services.Context, mm.Association, source, keyExprs, lex);
                // Convert
                QueryConverter qc = new QueryConverter(this.services, this.typeProvider, this, this.sql);
                SqlSelect sel = (SqlSelect)qc.ConvertInner(expr, link.SourceExpression);
                // Turn it into an expression is necessary
                SqlNode result = sel;
                if (asExpression) {
                    if (mm.Association.IsMany) {
                        result = new SqlSubSelect(SqlNodeType.Multiset, link.ClrType, link.SqlType, sel);
                    }
                    else {
                        result = new SqlSubSelect(SqlNodeType.Element, link.ClrType, link.SqlType, sel);
                    }
                }
                return result;
            }
            else {
                System.Diagnostics.Debug.Assert(link.Expansion != null);
                System.Diagnostics.Debug.Assert(link.KeyExpressions == keyExpressions);
                // deferred expression already defined...
                return link.Expansion;
            }
        }