public static IBuildContext BuildAssociationSelectMany(ExpressionBuilder builder, BuildInfo buildInfo, TableBuilder.TableContext tableContext, AccessorMember onMember, AssociationDescriptor descriptor, ref bool isOuter) { var elementType = descriptor.GetElementType(builder.MappingSchema); var queryMethod = CreateAssociationQueryLambda( builder, onMember, descriptor, tableContext.OriginalType, tableContext.ObjectType, elementType, false, isOuter, tableContext.LoadWith, out isOuter); var parentRef = new ContextRefExpression(queryMethod.Parameters[0].Type, tableContext); var body = queryMethod.GetBody(parentRef); IBuildContext context; context = builder.BuildSequence(new BuildInfo(buildInfo, body)); context.SelectQuery.From.Tables[0].Alias = descriptor.GenerateAlias(); return(context); }
public static IBuildContext BuildAssociationInline(ExpressionBuilder builder, BuildInfo buildInfo, TableBuilder.TableContext tableContext, AccessorMember onMember, AssociationDescriptor descriptor, bool inline, ref bool isOuter) { var elementType = descriptor.GetElementType(builder.MappingSchema); var parentExactType = descriptor.GetParentElementType(); var queryMethod = CreateAssociationQueryLambda( builder, onMember, descriptor, tableContext.OriginalType, parentExactType, elementType, inline, isOuter, tableContext.LoadWith, out isOuter); var parentRef = new ContextRefExpression(queryMethod.Parameters[0].Type, tableContext); var body = queryMethod.GetBody(parentRef); var context = builder.BuildSequence(new BuildInfo(tableContext, body, new SelectQuery())); var tableSource = tableContext.SelectQuery.From.Tables.First(); var join = new SqlFromClause.Join(isOuter ? JoinType.OuterApply : JoinType.CrossApply, context.SelectQuery, descriptor.GenerateAlias(), true, null); tableSource.Joins.Add(join.JoinedTable); return(new AssociationContext(builder, descriptor, tableContext, context, join.JoinedTable)); }