private static ObjectTypeMapping LoadObjectMapping( EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary <string, ObjectTypeMapping> typeMappings) { if (Helper.IsEnumType(edmType) ^ Helper.IsEnumType(objectType)) { throw new MappingException(Strings.Mapping_EnumTypeMappingToNonEnumType((object)edmType.FullName, (object)objectType.FullName)); } if (edmType.Abstract != objectType.Abstract) { throw new MappingException(Strings.Mapping_AbstractTypeMappingToNonAbstractType((object)edmType.FullName, (object)objectType.FullName)); } ObjectTypeMapping objectMapping = new ObjectTypeMapping(objectType, edmType); typeMappings.Add(edmType.FullName, objectMapping); if (Helper.IsEntityType(edmType) || Helper.IsComplexType(edmType)) { DefaultObjectMappingItemCollection.LoadEntityTypeOrComplexTypeMapping(objectMapping, edmType, objectType, ocItemCollection, typeMappings); } else if (Helper.IsEnumType(edmType)) { DefaultObjectMappingItemCollection.ValidateEnumTypeMapping((EnumType)edmType, (EnumType)objectType); } else { DefaultObjectMappingItemCollection.LoadAssociationTypeMapping(objectMapping, edmType, objectType, ocItemCollection, typeMappings); } return(objectMapping); }
private static ObjectTypeMapping LoadTypeMapping( EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary <string, ObjectTypeMapping> typeMappings) { ObjectTypeMapping objectTypeMapping; //First, check in the type mappings to find out if the mapping is already present if (typeMappings.TryGetValue(edmType.FullName, out objectTypeMapping)) { return(objectTypeMapping); } if (ocItemCollection != null) { ObjectTypeMapping typeMapping; if (ocItemCollection.ContainsMap(edmType, out typeMapping)) { return(typeMapping); } } // If the type mapping is not already loaded, then load it return(LoadObjectMapping(edmType, objectType, ocItemCollection, typeMappings)); }
private static ObjectComplexPropertyMapping LoadComplexMemberMapping( EdmProperty containingEdmMember, EdmProperty containingClrMember, DefaultObjectMappingItemCollection ocItemCollection, Dictionary <string, ObjectTypeMapping> typeMappings) { DefaultObjectMappingItemCollection.LoadTypeMapping(containingEdmMember.TypeUsage.EdmType, containingClrMember.TypeUsage.EdmType, ocItemCollection, typeMappings); return(new ObjectComplexPropertyMapping(containingEdmMember, containingClrMember)); }
// <summary> // Load the entity type or complex type mapping // </summary> private static void LoadEntityTypeOrComplexTypeMapping( ObjectTypeMapping objectMapping, EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary <string, ObjectTypeMapping> typeMappings) { Debug.Assert( edmType.BuiltInTypeKind == BuiltInTypeKind.EntityType || edmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType, "Expected Type Encountered in LoadEntityTypeOrComplexTypeMapping"); Debug.Assert( (edmType.BuiltInTypeKind == objectType.BuiltInTypeKind), "The BuiltInTypeKind must be same in LoadEntityTypeOrComplexTypeMapping"); var cdmStructuralType = (StructuralType)edmType; var objectStructuralType = (StructuralType)objectType; ValidateAllMembersAreMapped(cdmStructuralType, objectStructuralType); //Go through the CDMMembers and find the corresponding member in Object space //and create a member map. foreach (var edmMember in cdmStructuralType.Members) { var objectMember = GetObjectMember(edmMember, objectStructuralType); ValidateMembersMatch(edmMember, objectMember); if (Helper.IsEdmProperty(edmMember)) { var edmPropertyMember = (EdmProperty)edmMember; var edmPropertyObject = (EdmProperty)objectMember; //Depending on the type of member load the member mapping i.e. For complex //members we have to go in and load the child members of the Complex type. if (Helper.IsComplexType(edmMember.TypeUsage.EdmType)) { objectMapping.AddMemberMap( LoadComplexMemberMapping(edmPropertyMember, edmPropertyObject, ocItemCollection, typeMappings)); } else { objectMapping.AddMemberMap( LoadScalarPropertyMapping(edmPropertyMember, edmPropertyObject)); } } else { Debug.Assert(edmMember.BuiltInTypeKind == BuiltInTypeKind.NavigationProperty, "Unexpected Property type encountered"); // For navigation properties, we need to make sure the relationship type on the navigation property is mapped var navigationProperty = (NavigationProperty)edmMember; var objectNavigationProperty = (NavigationProperty)objectMember; LoadTypeMapping( navigationProperty.RelationshipType, objectNavigationProperty.RelationshipType, ocItemCollection, typeMappings); objectMapping.AddMemberMap(new ObjectNavigationPropertyMapping(navigationProperty, objectNavigationProperty)); } } }
internal static ObjectTypeMapping LoadObjectMapping( EdmType cdmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection) { Dictionary <string, ObjectTypeMapping> typeMappings = new Dictionary <string, ObjectTypeMapping>((IEqualityComparer <string>)StringComparer.Ordinal); ObjectTypeMapping objectTypeMapping = DefaultObjectMappingItemCollection.LoadObjectMapping(cdmType, objectType, ocItemCollection, typeMappings); ocItemCollection?.AddInternalMappings((IEnumerable <ObjectTypeMapping>)typeMappings.Values); return(objectTypeMapping); }
// <summary> // The method fills up the children of ObjectMapping. It goes through the // members in CDM type and finds the member in Object space with the same name // and creates a member map between them. These member maps are added // as children of the object mapping. // </summary> internal static ObjectTypeMapping LoadObjectMapping( EdmType cdmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection) { var typeMappings = new Dictionary <string, ObjectTypeMapping>(StringComparer.Ordinal); var typeMapping = LoadObjectMapping(cdmType, objectType, ocItemCollection, typeMappings); // If DefaultOCMappingItemCollection is not null, add all the type mappings to the item collection if (ocItemCollection != null) { ocItemCollection.AddInternalMappings(typeMappings.Values); } return(typeMapping); }
private static void ValidateMembersMatch(EdmMember edmMember, EdmMember objectMember) { if (edmMember.BuiltInTypeKind != objectMember.BuiltInTypeKind) { throw new MappingException(Strings.Mapping_Default_OCMapping_MemberKind_Mismatch((object)edmMember.Name, (object)edmMember.DeclaringType.FullName, (object)edmMember.BuiltInTypeKind, (object)objectMember.Name, (object)objectMember.DeclaringType.FullName, (object)objectMember.BuiltInTypeKind)); } if (edmMember.TypeUsage.EdmType.BuiltInTypeKind != objectMember.TypeUsage.EdmType.BuiltInTypeKind) { throw Error.Mapping_Default_OCMapping_Member_Type_Mismatch((object)edmMember.TypeUsage.EdmType.Name, (object)edmMember.TypeUsage.EdmType.BuiltInTypeKind, (object)edmMember.Name, (object)edmMember.DeclaringType.FullName, (object)objectMember.TypeUsage.EdmType.Name, (object)objectMember.TypeUsage.EdmType.BuiltInTypeKind, (object)objectMember.Name, (object)objectMember.DeclaringType.FullName); } if (Helper.IsPrimitiveType(edmMember.TypeUsage.EdmType)) { if (Helper.GetSpatialNormalizedPrimitiveType(edmMember.TypeUsage.EdmType).PrimitiveTypeKind != ((PrimitiveType)objectMember.TypeUsage.EdmType).PrimitiveTypeKind) { throw new MappingException(Strings.Mapping_Default_OCMapping_Invalid_MemberType((object)edmMember.TypeUsage.EdmType.FullName, (object)edmMember.Name, (object)edmMember.DeclaringType.FullName, (object)objectMember.TypeUsage.EdmType.FullName, (object)objectMember.Name, (object)objectMember.DeclaringType.FullName)); } } else if (Helper.IsEnumType(edmMember.TypeUsage.EdmType)) { DefaultObjectMappingItemCollection.ValidateEnumTypeMapping((EnumType)edmMember.TypeUsage.EdmType, (EnumType)objectMember.TypeUsage.EdmType); } else { EdmType edmType1; EdmType edmType2; if (edmMember.BuiltInTypeKind == BuiltInTypeKind.AssociationEndMember) { edmType1 = (EdmType)((RefType)edmMember.TypeUsage.EdmType).ElementType; edmType2 = (EdmType)((RefType)objectMember.TypeUsage.EdmType).ElementType; } else if (BuiltInTypeKind.NavigationProperty == edmMember.BuiltInTypeKind && Helper.IsCollectionType((GlobalItem)edmMember.TypeUsage.EdmType)) { edmType1 = ((CollectionType)edmMember.TypeUsage.EdmType).TypeUsage.EdmType; edmType2 = ((CollectionType)objectMember.TypeUsage.EdmType).TypeUsage.EdmType; } else { edmType1 = edmMember.TypeUsage.EdmType; edmType2 = objectMember.TypeUsage.EdmType; } if (edmType1.Identity != ObjectItemCollection.TryGetMappingCSpaceTypeIdentity(edmType2)) { throw new MappingException(Strings.Mapping_Default_OCMapping_Invalid_MemberType((object)edmMember.TypeUsage.EdmType.FullName, (object)edmMember.Name, (object)edmMember.DeclaringType.FullName, (object)objectMember.TypeUsage.EdmType.FullName, (object)objectMember.Name, (object)objectMember.DeclaringType.FullName)); } } }
private static ObjectTypeMapping LoadObjectMapping( EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary <string, ObjectTypeMapping> typeMappings) { DebugCheck.NotNull(edmType); DebugCheck.NotNull(objectType); if (Helper.IsEnumType(edmType) ^ Helper.IsEnumType(objectType)) { throw new MappingException(Strings.Mapping_EnumTypeMappingToNonEnumType(edmType.FullName, objectType.FullName)); } // Check if both the types are abstract or both of them are not if (edmType.Abstract != objectType.Abstract) { throw new MappingException(Strings.Mapping_AbstractTypeMappingToNonAbstractType(edmType.FullName, objectType.FullName)); } var objectTypeMapping = new ObjectTypeMapping(objectType, edmType); typeMappings.Add(edmType.FullName, objectTypeMapping); if (Helper.IsEntityType(edmType) || Helper.IsComplexType(edmType)) { LoadEntityTypeOrComplexTypeMapping(objectTypeMapping, edmType, objectType, ocItemCollection, typeMappings); } else if (Helper.IsEnumType(edmType)) { ValidateEnumTypeMapping((EnumType)edmType, (EnumType)objectType); } else { Debug.Assert(Helper.IsAssociationType(edmType)); LoadAssociationTypeMapping(objectTypeMapping, edmType, objectType, ocItemCollection, typeMappings); } return(objectTypeMapping); }
private static ObjectTypeMapping LoadTypeMapping( EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary <string, ObjectTypeMapping> typeMappings) { ObjectTypeMapping objectTypeMapping; if (typeMappings.TryGetValue(edmType.FullName, out objectTypeMapping)) { return(objectTypeMapping); } ObjectTypeMapping map; if (ocItemCollection != null && ocItemCollection.ContainsMap((GlobalItem)edmType, out map)) { return(map); } return(DefaultObjectMappingItemCollection.LoadObjectMapping(edmType, objectType, ocItemCollection, typeMappings)); }
// <summary> // The method loads the EdmMember mapping for complex members. // It goes through the CDM members of the Complex Cdm type and // tries to find the corresponding members in Complex Clr type. // </summary> private static ObjectComplexPropertyMapping LoadComplexMemberMapping( EdmProperty containingEdmMember, EdmProperty containingClrMember, DefaultObjectMappingItemCollection ocItemCollection, Dictionary <string, ObjectTypeMapping> typeMappings) { Debug.Assert( containingEdmMember.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType, "edm member declaringType must be of complexType"); Debug.Assert( containingClrMember.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType, "clr member declaringType must be of complexType"); var edmComplexType = (ComplexType)containingEdmMember.TypeUsage.EdmType; var objectComplexType = (ComplexType)containingClrMember.TypeUsage.EdmType; // Get the type mapping for the complex type LoadTypeMapping(edmComplexType, objectComplexType, ocItemCollection, typeMappings); //Go through the CDMMembers and find the corresponding member in Object space //and create a member map. return(new ObjectComplexPropertyMapping(containingEdmMember, containingClrMember)); }
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)); } }
// <summary> // Loads Association Type Mapping // </summary> private static void LoadAssociationTypeMapping( ObjectTypeMapping objectMapping, EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary <string, ObjectTypeMapping> typeMappings) { Debug.Assert( edmType.BuiltInTypeKind == BuiltInTypeKind.AssociationType, "Expected Type Encountered in LoadAssociationTypeMapping"); Debug.Assert( (edmType.BuiltInTypeKind == objectType.BuiltInTypeKind), "The BuiltInTypeKind must be same in LoadAssociationTypeMapping"); var association = (AssociationType)edmType; var objectAssociation = (AssociationType)objectType; foreach (var edmEnd in association.AssociationEndMembers) { var objectEnd = (AssociationEndMember)GetObjectMember(edmEnd, objectAssociation); ValidateMembersMatch(edmEnd, objectEnd); if (edmEnd.RelationshipMultiplicity != objectEnd.RelationshipMultiplicity) { throw new MappingException( Strings.Mapping_Default_OCMapping_MultiplicityMismatch( edmEnd.RelationshipMultiplicity, edmEnd.Name, association.FullName, objectEnd.RelationshipMultiplicity, objectEnd.Name, objectAssociation.FullName)); } Debug.Assert(edmEnd.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.RefType, "Ends must be of Ref type"); // GetMap for the entity types for the ends of the relationship type to make sure // the entity type mentioned are valid LoadTypeMapping( ((RefType)edmEnd.TypeUsage.EdmType).ElementType, ((RefType)objectEnd.TypeUsage.EdmType).ElementType, ocItemCollection, typeMappings); objectMapping.AddMemberMap(new ObjectAssociationEndMapping(edmEnd, objectEnd)); } }
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)); } } }
/// <summary> /// Loads Association Type Mapping /// </summary> /// <param name="objectMapping"></param> /// <param name="edmType"></param> /// <param name="objectType"></param> /// <param name="ocItemCollection"></param> /// <param name="typeMappings"></param> private static void LoadAssociationTypeMapping( ObjectTypeMapping objectMapping, EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary<string, ObjectTypeMapping> typeMappings) { Debug.Assert( edmType.BuiltInTypeKind == BuiltInTypeKind.AssociationType, "Expected Type Encountered in LoadAssociationTypeMapping"); Debug.Assert( (edmType.BuiltInTypeKind == objectType.BuiltInTypeKind), "The BuiltInTypeKind must be same in LoadAssociationTypeMapping"); var association = (AssociationType)edmType; var objectAssociation = (AssociationType)objectType; foreach (var edmEnd in association.AssociationEndMembers) { var objectEnd = (AssociationEndMember)GetObjectMember(edmEnd, objectAssociation); ValidateMembersMatch(edmEnd, objectEnd); if (edmEnd.RelationshipMultiplicity != objectEnd.RelationshipMultiplicity) { throw new MappingException( Strings.Mapping_Default_OCMapping_MultiplicityMismatch( edmEnd.RelationshipMultiplicity, edmEnd.Name, association.FullName, objectEnd.RelationshipMultiplicity, objectEnd.Name, objectAssociation.FullName)); } Debug.Assert(edmEnd.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.RefType, "Ends must be of Ref type"); // GetMap for the entity types for the ends of the relationship type to make sure // the entity type mentioned are valid LoadTypeMapping( ((RefType)edmEnd.TypeUsage.EdmType).ElementType, ((RefType)objectEnd.TypeUsage.EdmType).ElementType, ocItemCollection, typeMappings); objectMapping.AddMemberMap(new ObjectAssociationEndMapping(edmEnd, objectEnd)); } }
/// <summary> /// Load the entity type or complex type mapping /// </summary> /// <param name="objectMapping"></param> /// <param name="edmType"></param> /// <param name="objectType"></param> /// <param name="ocItemCollection"> /// <param name="typeMappings"></param></param> private static void LoadEntityTypeOrComplexTypeMapping( ObjectTypeMapping objectMapping, EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary<string, ObjectTypeMapping> typeMappings) { Debug.Assert( edmType.BuiltInTypeKind == BuiltInTypeKind.EntityType || edmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType, "Expected Type Encountered in LoadEntityTypeOrComplexTypeMapping"); Debug.Assert( (edmType.BuiltInTypeKind == objectType.BuiltInTypeKind), "The BuiltInTypeKind must be same in LoadEntityTypeOrComplexTypeMapping"); var cdmStructuralType = (StructuralType)edmType; var objectStructuralType = (StructuralType)objectType; ValidateAllMembersAreMapped(cdmStructuralType, objectStructuralType); //Go through the CDMMembers and find the corresponding member in Object space //and create a member map. foreach (var edmMember in cdmStructuralType.Members) { var objectMember = GetObjectMember(edmMember, objectStructuralType); ValidateMembersMatch(edmMember, objectMember); if (Helper.IsEdmProperty(edmMember)) { var edmPropertyMember = (EdmProperty)edmMember; var edmPropertyObject = (EdmProperty)objectMember; //Depending on the type of member load the member mapping i.e. For complex //members we have to go in and load the child members of the Complex type. if (Helper.IsComplexType(edmMember.TypeUsage.EdmType)) { objectMapping.AddMemberMap( LoadComplexMemberMapping(edmPropertyMember, edmPropertyObject, ocItemCollection, typeMappings)); } else { objectMapping.AddMemberMap( LoadScalarPropertyMapping(edmPropertyMember, edmPropertyObject)); } } else { Debug.Assert(edmMember.BuiltInTypeKind == BuiltInTypeKind.NavigationProperty, "Unexpected Property type encountered"); // For navigation properties, we need to make sure the relationship type on the navigation property is mapped var navigationProperty = (NavigationProperty)edmMember; var objectNavigationProperty = (NavigationProperty)objectMember; LoadTypeMapping( navigationProperty.RelationshipType, objectNavigationProperty.RelationshipType, ocItemCollection, typeMappings); objectMapping.AddMemberMap(new ObjectNavigationPropertyMapping(navigationProperty, objectNavigationProperty)); } } }
private static ObjectTypeMapping LoadObjectMapping( EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary<string, ObjectTypeMapping> typeMappings) { Debug.Assert((edmType != null) && (objectType != null)); Debug.Assert((edmType.BuiltInTypeKind == objectType.BuiltInTypeKind), "The BuiltInTypeKind must be same in LoadObjectMapping"); if (Helper.IsEnumType(edmType) ^ Helper.IsEnumType(objectType)) { throw new MappingException(Strings.Mapping_EnumTypeMappingToNonEnumType(edmType.FullName, objectType.FullName)); } // Check if both the types are abstract or both of them are not if (edmType.Abstract != objectType.Abstract) { throw new MappingException(Strings.Mapping_AbstractTypeMappingToNonAbstractType(edmType.FullName, objectType.FullName)); } var objectTypeMapping = new ObjectTypeMapping(objectType, edmType); typeMappings.Add(edmType.FullName, objectTypeMapping); if (Helper.IsEntityType(edmType) || Helper.IsComplexType(edmType)) { LoadEntityTypeOrComplexTypeMapping(objectTypeMapping, edmType, objectType, ocItemCollection, typeMappings); } else if (Helper.IsEnumType(edmType)) { ValidateEnumTypeMapping((EnumType)edmType, (EnumType)objectType); } else { Debug.Assert(Helper.IsAssociationType(edmType)); LoadAssociationTypeMapping(objectTypeMapping, edmType, objectType, ocItemCollection, typeMappings); } return objectTypeMapping; }
/// <summary> /// The method fills up the children of ObjectMapping. It goes through the /// members in CDM type and finds the member in Object space with the same name /// and creates a member map between them. These member maps are added /// as children of the object mapping. /// </summary> /// <param name="cdmType"></param> /// <param name="objectType"></param> /// <param name="ocItemCollection"></param> internal static ObjectTypeMapping LoadObjectMapping( EdmType cdmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection) { var typeMappings = new Dictionary<string, ObjectTypeMapping>(StringComparer.Ordinal); var typeMapping = LoadObjectMapping(cdmType, objectType, ocItemCollection, typeMappings); // If DefaultOCMappingItemCollection is not null, add all the type mappings to the item collection if (ocItemCollection != null) { foreach (var map in typeMappings.Values) { ocItemCollection.AddInternalMapping(map); } } return typeMapping; }
private MappingBase GetDefaultMapping(EdmType cdmType, EdmType clrType) { return((MappingBase)DefaultObjectMappingItemCollection.LoadObjectMapping(cdmType, clrType, this)); }
public void Registering_c_space_or_o_space_does_not_cause_oc_mapping_to_be_registered_if_it_is_already_registered() { var edmItemCollection = new EdmItemCollection(new[] { XDocument.Parse(_csdlV3).CreateReader() }); var objectItemCollection = new ObjectItemCollection(); var ocMappingItemCollection = new DefaultObjectMappingItemCollection(edmItemCollection, objectItemCollection); var workspace = new MetadataWorkspace(); #pragma warning disable 612,618 workspace.RegisterItemCollection(ocMappingItemCollection); workspace.RegisterItemCollection(edmItemCollection); workspace.RegisterItemCollection(objectItemCollection); #pragma warning restore 612,618 Assert.Same(ocMappingItemCollection, workspace.GetItemCollection(DataSpace.OCSpace)); Assert.Same(edmItemCollection, workspace.GetItemCollection(DataSpace.CSpace)); Assert.Same(objectItemCollection, workspace.GetItemCollection(DataSpace.OSpace)); }
/// <summary> /// The method loads the EdmMember mapping for complex members. /// It goes through the CDM members of the Complex Cdm type and /// tries to find the corresponding members in Complex Clr type. /// </summary> /// <param name="containingEdmMember"></param> /// <param name="containingClrMember"></param> /// <param name="ocItemCollection"></param> /// <param name="typeMappings"></param> /// <returns></returns> private static ObjectComplexPropertyMapping LoadComplexMemberMapping( EdmProperty containingEdmMember, EdmProperty containingClrMember, DefaultObjectMappingItemCollection ocItemCollection, Dictionary<string, ObjectTypeMapping> typeMappings) { Debug.Assert( containingEdmMember.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType, "edm member declaringType must be of complexType"); Debug.Assert( containingClrMember.TypeUsage.EdmType.BuiltInTypeKind == BuiltInTypeKind.ComplexType, "clr member declaringType must be of complexType"); var edmComplexType = (ComplexType)containingEdmMember.TypeUsage.EdmType; var objectComplexType = (ComplexType)containingClrMember.TypeUsage.EdmType; // Get the type mapping for the complex type var complexTypeMapping = LoadTypeMapping(edmComplexType, objectComplexType, ocItemCollection, typeMappings); //Go through the CDMMembers and find the corresponding member in Object space //and create a member map. return new ObjectComplexPropertyMapping(containingEdmMember, containingClrMember); }
private static ObjectTypeMapping LoadTypeMapping( EdmType edmType, EdmType objectType, DefaultObjectMappingItemCollection ocItemCollection, Dictionary<string, ObjectTypeMapping> typeMappings) { ObjectTypeMapping objectTypeMapping; //First, check in the type mappings to find out if the mapping is already present if (typeMappings.TryGetValue(edmType.FullName, out objectTypeMapping)) { return objectTypeMapping; } if (ocItemCollection != null) { ObjectTypeMapping typeMapping; if (ocItemCollection.ContainsMap(edmType, out typeMapping)) { return typeMapping; } } // If the type mapping is not already loaded, then load it return LoadObjectMapping(edmType, objectType, ocItemCollection, typeMappings); }
private static void Item_collections_can_be_registered(MetadataWorkspace workspace) { var edmItemCollection = new EdmItemCollection(new[] { XDocument.Parse(_csdlV3).CreateReader() }); var storeItemCollection = new StoreItemCollection(new[] { XDocument.Parse(_ssdlV3).CreateReader() }); var objectItemCollection = new ObjectItemCollection(); var storageMappingItemCollection = LoadMsl(edmItemCollection, storeItemCollection); var ocMappingItemCollection = new DefaultObjectMappingItemCollection(edmItemCollection, objectItemCollection); #pragma warning disable 612,618 workspace.RegisterItemCollection(edmItemCollection); workspace.RegisterItemCollection(storeItemCollection); workspace.RegisterItemCollection(objectItemCollection); workspace.RegisterItemCollection(storageMappingItemCollection); workspace.RegisterItemCollection(ocMappingItemCollection); #pragma warning restore 612,618 Assert.Same(edmItemCollection, workspace.GetItemCollection(DataSpace.CSpace)); Assert.Same(storeItemCollection, workspace.GetItemCollection(DataSpace.SSpace)); Assert.Same(storageMappingItemCollection, workspace.GetItemCollection(DataSpace.CSSpace)); Assert.Same(objectItemCollection, workspace.GetItemCollection(DataSpace.OSpace)); Assert.Same(ocMappingItemCollection, workspace.GetItemCollection(DataSpace.OCSpace)); }