public Model(ISessionFactory sessionfactory, ComponentType type) { if (type == null) { throw new ArgumentNullException("type"); } IsComponent = true; Type = type.ReturnedClass; ComponentType = type; Metadata = sessionfactory.GetClassMetadata(Type); Properties = new Dictionary <string, IType>(); Components = new Dictionary <string, Model>(); BelongsTos = new Dictionary <string, ManyToOneType>(); OneToOnes = new Dictionary <string, OneToOneType>(); Anys = new Dictionary <string, AnyType>(); HasManys = new Dictionary <string, Collection>(); HasAndBelongsToManys = new Dictionary <string, Collection>(); foreach (var pc in type.PropertyNames) { var index = type.GetPropertyIndex(pc); var x = type.Subtypes[index]; CategorizeProperty(sessionfactory, x, pc); } }
private void Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, HqlDot memberPath, IType propType) { if (resultOperator is FetchOneRequest) { if (propType == null) { var metadata = queryModelVisitor.VisitorParameters.SessionFactory .GetClassMetadata(resultOperator.RelationMember.ReflectedType); propType = metadata?.GetPropertyType(resultOperator.RelationMember.Name); } if (propType != null && !propType.IsAssociationType) { tree.AddFromLastChildClause(tree.TreeBuilder.Fetch()); tree.AddFromLastChildClause(memberPath); ComponentType componentType = null; foreach (var innerFetch in resultOperator.InnerFetchRequests) { if (componentType == null) { componentType = propType as ComponentType; if (componentType == null) { throw new InvalidOperationException( $"Property {innerFetch.RelationMember.Name} cannot be fetched from a non component type property {resultOperator.RelationMember.Name}."); } } var subTypeIndex = componentType.GetPropertyIndex(innerFetch.RelationMember.Name); memberPath = tree.TreeBuilder.Dot( memberPath, tree.TreeBuilder.Ident(innerFetch.RelationMember.Name)); Process(innerFetch, queryModelVisitor, tree, memberPath, componentType.Subtypes[subTypeIndex]); } return; } } var alias = queryModelVisitor.Model.GetNewName("_"); tree.AddFromClause(tree.TreeBuilder.LeftFetchJoin(memberPath, tree.TreeBuilder.Alias(alias))); tree.AddDistinctRootOperator(); foreach (var innerFetch in resultOperator.InnerFetchRequests) { Process(innerFetch, queryModelVisitor, tree, alias); } }
private void Process( FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, HqlDot memberPath, HqlTreeNode currentNode, IType propType) { string alias = null; if (resultOperator is FetchOneRequest) { if (propType == null) { var metadata = queryModelVisitor.VisitorParameters.SessionFactory .GetClassMetadata(resultOperator.RelationMember.ReflectedType); propType = metadata?.GetPropertyType(resultOperator.RelationMember.Name); } if (propType != null && !propType.IsAssociationType) { if (currentNode == null) { currentNode = tree.GetFromRangeClause() ?? throw new InvalidOperationException($"Property {resultOperator.RelationMember.Name} cannot be fetched for this type of query."); } currentNode.AddChild(tree.TreeBuilder.Fetch()); currentNode.AddChild(memberPath); ComponentType componentType = null; foreach (var innerFetch in resultOperator.InnerFetchRequests) { if (componentType == null) { componentType = propType as ComponentType; if (componentType == null) { throw new InvalidOperationException( $"Property {innerFetch.RelationMember.Name} cannot be fetched from a non component type property {resultOperator.RelationMember.Name}."); } } var subTypeIndex = componentType.GetPropertyIndex(innerFetch.RelationMember.Name); memberPath = tree.TreeBuilder.Dot( memberPath, tree.TreeBuilder.Ident(innerFetch.RelationMember.Name)); Process(innerFetch, queryModelVisitor, tree, memberPath, currentNode, componentType.Subtypes[subTypeIndex]); } return; } var relatedJoin = queryModelVisitor.RelatedJoinFetchRequests.FirstOrDefault(o => o.Value == resultOperator).Key; if (relatedJoin != null) { alias = queryModelVisitor.VisitorParameters.QuerySourceNamer.GetName(relatedJoin); } } if (alias == null) { alias = queryModelVisitor.Model.GetNewName("_"); currentNode = tree.TreeBuilder.LeftFetchJoin(memberPath, tree.TreeBuilder.Alias(alias)); tree.AddFromClause(currentNode); } tree.AddDistinctRootOperator(); foreach (var innerFetch in resultOperator.InnerFetchRequests) { Process(innerFetch, queryModelVisitor, tree, currentNode, alias); } }