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);
            }
        }
Beispiel #2
0
        /// <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);
            }
        }