private void CreateStubEntityTypes(QueryTypeLibrary library, EntityContainer container) { foreach (var entitySet in container.EntitySets) { var rootType = entitySet.EntityType; var allDerivedTypes = container.Model.EntityTypes.Where(et => et.IsKindOf(rootType)); foreach (var entityType in allDerivedTypes) { QueryEntityType stub = this.CreateStubEntityType(entityType, entitySet); library.SetQueryEntityType(entitySet, entityType, stub); } // set up Parent for each type foreach (var childType in allDerivedTypes.Where(et => et != rootType)) { library.GetQueryEntityType(entitySet, childType).Parent = library.GetQueryEntityType(entitySet, childType.BaseType); } } // TODO: maybe this is wrong if >1 containers! Add unit test and fix. // construct DerivedTypes for each type foreach (var type in library.GetQueryEntityTypes()) { for (var parent = type.Parent; parent != null; parent = parent.Parent) { parent.DerivedTypes.Add(type); } } }
private void CreateNavigationMembers(QueryTypeLibrary library, QueryEntityType result, IEnumerable <NavigationProperty> navigationProperties, EntityContainer container) { foreach (var navprop in navigationProperties) { // handle MEST scenario where there are multiple association sets corresponding to a navigation property var asets = container.AssociationSets.Where(c => c.AssociationType == navprop.Association); var aset = asets.Single(set => set.Ends.Any(end => end.AssociationEnd == navprop.FromAssociationEnd && end.EntitySet == result.EntitySet)); var toSet = aset.Ends.Single(e => e.AssociationEnd == navprop.ToAssociationEnd).EntitySet; var targetEntityType = library.GetQueryEntityType(toSet, navprop.ToAssociationEnd.EntityType); QueryProperty property; if (navprop.ToAssociationEnd.Multiplicity == EndMultiplicity.Many) { // collection property property = QueryProperty.Create(navprop.Name, targetEntityType.CreateCollectionType()); } else { // reference property property = QueryProperty.Create(navprop.Name, targetEntityType); } result.Add(property); } }
private void BuildStructuralTypes(QueryTypeLibrary library, EntityContainer container) { foreach (var entitySet in container.EntitySets) { var rootType = entitySet.EntityType; var allDerivedTypes = container.Model.EntityTypes.Where(et => et.IsKindOf(rootType)); foreach (var entityType in allDerivedTypes) { var queryEntityType = library.GetQueryEntityType(entitySet, entityType); var pathToProperty = new PathToProperty(container, entitySet, entityType); this.CreateMembers(library, queryEntityType, entityType.AllProperties, pathToProperty); ExceptionUtilities.Assert(pathToProperty.PathStackWithinEntityType.Count == 0, "Path to property stack is not empty."); this.CreateNavigationMembers(library, queryEntityType, entityType.AllNavigationProperties, container); } } }
/// <summary> /// Build Library Without Clr Type Mappings based on the EntityModelSchema given /// </summary> /// <param name="model">Entity Model Schema to create Query Model of</param> /// <returns>Query Type Library of Entity Model Schema</returns> public override QueryTypeLibrary BuildLibraryWithoutClrTypeMapping(EntityModelSchema model) { QueryTypeLibrary queryTypeLibrary = base.BuildLibraryWithoutClrTypeMapping(model); // add new properties for each of the named streams annotations to the query entity type to be used for verification foreach (var container in model.EntityContainers) { foreach (var entitySet in container.EntitySets) { foreach (EntityType entityType in model.EntityTypes.Where(t => t.IsKindOf(entitySet.EntityType))) { QueryEntityType queryEntityType = queryTypeLibrary.GetQueryEntityType(entitySet, entityType); // add the named streams properties foreach (var streamProperty in queryEntityType.EntityType.Properties.Where(p => p.IsStream())) { queryEntityType.Add(new QueryProperty <AstoriaQueryStreamType>(streamProperty.Name, new AstoriaQueryStreamType(this.strategy))); foreach (QueryEntityType qet in queryEntityType.DerivedTypes) { qet.Add(new QueryProperty <AstoriaQueryStreamType>(streamProperty.Name, new AstoriaQueryStreamType(this.strategy))); } } // add the default stream property if (entityType.HasStream()) { var queryStreamType = new AstoriaQueryStreamType(this.strategy); queryEntityType.Add(new QueryProperty <AstoriaQueryStreamType>(AstoriaQueryStreamType.DefaultStreamPropertyName, queryStreamType)); foreach (QueryEntityType qet in queryEntityType.DerivedTypes) { qet.Add(new QueryProperty <AstoriaQueryStreamType>(AstoriaQueryStreamType.DefaultStreamPropertyName, new AstoriaQueryStreamType(this.strategy))); } } } } } return(queryTypeLibrary); }
private void CreateNavigationMembers(QueryTypeLibrary library, QueryEntityType result, IEnumerable<NavigationProperty> navigationProperties, EntityContainer container) { foreach (var navprop in navigationProperties) { // handle MEST scenario where there are multiple association sets corresponding to a navigation property var asets = container.AssociationSets.Where(c => c.AssociationType == navprop.Association); var aset = asets.Single(set => set.Ends.Any(end => end.AssociationEnd == navprop.FromAssociationEnd && end.EntitySet == result.EntitySet)); var toSet = aset.Ends.Single(e => e.AssociationEnd == navprop.ToAssociationEnd).EntitySet; var targetEntityType = library.GetQueryEntityType(toSet, navprop.ToAssociationEnd.EntityType); QueryProperty property; if (navprop.ToAssociationEnd.Multiplicity == EndMultiplicity.Many) { // collection property property = QueryProperty.Create(navprop.Name, targetEntityType.CreateCollectionType()); } else { // reference property property = QueryProperty.Create(navprop.Name, targetEntityType); } result.Add(property); } }
private void BuildStructuralTypes(QueryTypeLibrary library, EntityContainer container) { foreach (var entitySet in container.EntitySets) { var rootType = entitySet.EntityType; var allDerivedTypes = container.Model.EntityTypes.Where(et => et.IsKindOf(rootType)); foreach (var entityType in allDerivedTypes) { var queryEntityType = library.GetQueryEntityType(entitySet, entityType); var pathToProperty = new PathToProperty(container, entitySet, entityType); this.CreateMembers(library, queryEntityType, entityType.AllProperties, pathToProperty); ExceptionUtilities.Assert(pathToProperty.PathStackWithinEntityType.Count == 0, "Path to property stack is not empty."); this.CreateNavigationMembers(library, queryEntityType, entityType.AllNavigationProperties, container); } } }
private void CreateStubEntityTypes(QueryTypeLibrary library, EntityContainer container) { foreach (var entitySet in container.EntitySets) { var rootType = entitySet.EntityType; var allDerivedTypes = container.Model.EntityTypes.Where(et => et.IsKindOf(rootType)); foreach (var entityType in allDerivedTypes) { QueryEntityType stub = this.CreateStubEntityType(entityType, entitySet); library.SetQueryEntityType(entitySet, entityType, stub); } // set up Parent for each type foreach (var childType in allDerivedTypes.Where(et => et != rootType)) { library.GetQueryEntityType(entitySet, childType).Parent = library.GetQueryEntityType(entitySet, childType.BaseType); } } // TODO: maybe this is wrong if >1 containers! Add unit test and fix. // construct DerivedTypes for each type foreach (var type in library.GetQueryEntityTypes()) { for (var parent = type.Parent; parent != null; parent = parent.Parent) { parent.DerivedTypes.Add(type); } } }