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); }
internal SqlMember Member(SqlExpression expr, MemberInfo member) { var memberType = TypeSystem.GetMemberType(member); var metaType = model.GetMetaType(member.DeclaringType); var dataMember = metaType.GetDataMember(member); if (metaType != null && dataMember != null) { return(new SqlMember(memberType, Default(dataMember), expr, member)); } return(new SqlMember(memberType, Default(memberType), expr, member)); }
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); } }
internal SqlMember Member(SqlExpression expr, MemberInfo member) { Type clrType = TypeSystem.GetMemberType(member); MetaType metaType = this.model.GetMetaType(member.DeclaringType); MetaDataMember metaDataMember = metaType.GetDataMember(member); if (metaType != null && metaDataMember != null) { return(new SqlMember(clrType, this.Default(metaDataMember), expr, member)); } else { return(new SqlMember(clrType, this.Default(clrType), expr, member)); } }