private static NavigationProperty ConvertToNavigationProperty(
            EntityType declaringEntityType,
            System.Data.Entity.Core.SchemaObjectModel.NavigationProperty somNavigationProperty,
            DbProviderManifest providerManifest,
            Converter.ConversionCache convertedItemCache,
            Dictionary <SchemaElement, GlobalItem> newGlobalItems)
        {
            EntityType       endMemberType   = (EntityType)Converter.LoadSchemaElement(somNavigationProperty.Type, providerManifest, convertedItemCache, newGlobalItems);
            AssociationType  associationType = (AssociationType)Converter.LoadSchemaElement((System.Data.Entity.Core.SchemaObjectModel.SchemaType)somNavigationProperty.Relationship, providerManifest, convertedItemCache, newGlobalItems);
            IRelationshipEnd end             = (IRelationshipEnd)null;

            somNavigationProperty.Relationship.TryGetEnd(somNavigationProperty.ToEnd.Name, out end);
            RelationshipMultiplicity?multiplicity1 = end.Multiplicity;
            EdmType edmType = (multiplicity1.GetValueOrDefault() != RelationshipMultiplicity.Many ? 0 : (multiplicity1.HasValue ? 1 : 0)) == 0 ? (EdmType)endMemberType : (EdmType)endMemberType.GetCollectionType();
            RelationshipMultiplicity?multiplicity2 = end.Multiplicity;
            TypeUsage typeUsage;

            if ((multiplicity2.GetValueOrDefault() != RelationshipMultiplicity.One ? 0 : (multiplicity2.HasValue ? 1 : 0)) != 0)
            {
                typeUsage = TypeUsage.Create(edmType, new FacetValues()
                {
                    Nullable = (FacetValueContainer <bool?>) new bool?(false)
                });
            }
            else
            {
                typeUsage = TypeUsage.Create(edmType);
            }
            Converter.InitializeAssociationEndMember(associationType, somNavigationProperty.ToEnd, endMemberType);
            Converter.InitializeAssociationEndMember(associationType, somNavigationProperty.FromEnd, declaringEntityType);
            NavigationProperty navigationProperty = new NavigationProperty(somNavigationProperty.Name, typeUsage);

            navigationProperty.RelationshipType = (RelationshipType)associationType;
            navigationProperty.ToEndMember      = (RelationshipEndMember)associationType.Members[somNavigationProperty.ToEnd.Name];
            navigationProperty.FromEndMember    = (RelationshipEndMember)associationType.Members[somNavigationProperty.FromEnd.Name];
            if (somNavigationProperty.Documentation != null)
            {
                navigationProperty.Documentation = Converter.ConvertToDocumentation(somNavigationProperty.Documentation);
            }
            Converter.AddOtherContent((SchemaElement)somNavigationProperty, (MetadataItem)navigationProperty);
            return(navigationProperty);
        }
Exemple #2
0
 private void HandleNavigationPropertyElement(XmlReader reader)
 {
     var navigationProperty = new NavigationProperty(this);
     navigationProperty.Parse(reader);
     AddMember(navigationProperty);
 }