Esempio n. 1
0
        private static void LoadAssociationTypeMapping(
            ObjectTypeMapping objectMapping,
            EdmType edmType,
            EdmType objectType,
            DefaultObjectMappingItemCollection ocItemCollection,
            Dictionary <string, ObjectTypeMapping> typeMappings)
        {
            AssociationType associationType1 = (AssociationType)edmType;
            AssociationType associationType2 = (AssociationType)objectType;

            foreach (AssociationEndMember associationEndMember in associationType1.AssociationEndMembers)
            {
                AssociationEndMember objectMember = (AssociationEndMember)DefaultObjectMappingItemCollection.GetObjectMember((EdmMember)associationEndMember, (StructuralType)associationType2);
                DefaultObjectMappingItemCollection.ValidateMembersMatch((EdmMember)associationEndMember, (EdmMember)objectMember);
                if (associationEndMember.RelationshipMultiplicity != objectMember.RelationshipMultiplicity)
                {
                    throw new MappingException(Strings.Mapping_Default_OCMapping_MultiplicityMismatch((object)associationEndMember.RelationshipMultiplicity, (object)associationEndMember.Name, (object)associationType1.FullName, (object)objectMember.RelationshipMultiplicity, (object)objectMember.Name, (object)associationType2.FullName));
                }
                DefaultObjectMappingItemCollection.LoadTypeMapping((EdmType)((RefType)associationEndMember.TypeUsage.EdmType).ElementType, (EdmType)((RefType)objectMember.TypeUsage.EdmType).ElementType, ocItemCollection, typeMappings);
                objectMapping.AddMemberMap((ObjectMemberMapping) new ObjectAssociationEndMapping(associationEndMember, objectMember));
            }
        }
Esempio n. 2
0
        private static void LoadEntityTypeOrComplexTypeMapping(
            ObjectTypeMapping objectMapping,
            EdmType edmType,
            EdmType objectType,
            DefaultObjectMappingItemCollection ocItemCollection,
            Dictionary <string, ObjectTypeMapping> typeMappings)
        {
            StructuralType cdmStructuralType = (StructuralType)edmType;
            StructuralType structuralType    = (StructuralType)objectType;

            DefaultObjectMappingItemCollection.ValidateAllMembersAreMapped(cdmStructuralType, structuralType);
            foreach (EdmMember member in cdmStructuralType.Members)
            {
                EdmMember objectMember = DefaultObjectMappingItemCollection.GetObjectMember(member, structuralType);
                DefaultObjectMappingItemCollection.ValidateMembersMatch(member, objectMember);
                if (Helper.IsEdmProperty(member))
                {
                    EdmProperty edmProperty1 = (EdmProperty)member;
                    EdmProperty edmProperty2 = (EdmProperty)objectMember;
                    if (Helper.IsComplexType(member.TypeUsage.EdmType))
                    {
                        objectMapping.AddMemberMap((ObjectMemberMapping)DefaultObjectMappingItemCollection.LoadComplexMemberMapping(edmProperty1, edmProperty2, ocItemCollection, typeMappings));
                    }
                    else
                    {
                        objectMapping.AddMemberMap((ObjectMemberMapping)DefaultObjectMappingItemCollection.LoadScalarPropertyMapping(edmProperty1, edmProperty2));
                    }
                }
                else
                {
                    NavigationProperty edmNavigationProperty = (NavigationProperty)member;
                    NavigationProperty clrNavigationProperty = (NavigationProperty)objectMember;
                    DefaultObjectMappingItemCollection.LoadTypeMapping((EdmType)edmNavigationProperty.RelationshipType, (EdmType)clrNavigationProperty.RelationshipType, ocItemCollection, typeMappings);
                    objectMapping.AddMemberMap((ObjectMemberMapping) new ObjectNavigationPropertyMapping(edmNavigationProperty, clrNavigationProperty));
                }
            }
        }