public void GetEntitySetMappingCache_produces_multiple_entitysets_for_single_clr_type_present_in_multiple_models() { var blogType = typeof(Blog); Internal.EntitySetTypePair blog1PairForBlogType; using (var blog1 = new BlogDbContext()) { using (var blog2 = new BlogDbContextVersion2()) { //obtain the type to entityset dictionaries and update the mappings var workspace1 = ((IObjectContextAdapter)blog1).ObjectContext.MetadataWorkspace.MetadataOptimization; var entitySetMappingCache1 = workspace1.EntitySetMappingCache; workspace1.TryUpdateEntitySetMappingsForType(blogType); var workspace2 = ((IObjectContextAdapter)blog2).ObjectContext.MetadataWorkspace.MetadataOptimization; var entitySetMappingCache2 = workspace2.EntitySetMappingCache; workspace2.TryUpdateEntitySetMappingsForType(blogType); //check that the same clr type maps to different entity sets on different metadata workspaces blog1PairForBlogType = entitySetMappingCache1[blogType]; Assert.NotNull(blog1PairForBlogType); Assert.False( ReferenceEquals(blog1PairForBlogType, entitySetMappingCache2[blogType]), "Single CLR type on two different metadata workspaces erroneously maps to the same entity set instance"); } } using (var blog1Bis = new BlogDbContext()) { var workspace1Bis = ((IObjectContextAdapter)blog1Bis).ObjectContext.MetadataWorkspace.MetadataOptimization; var entitySetMappingCache1Bis = workspace1Bis.EntitySetMappingCache; workspace1Bis.TryUpdateEntitySetMappingsForType(blogType); Assert.True( blog1PairForBlogType.Equals(entitySetMappingCache1Bis[blogType]), "Metadata workspace should produce same entity set for same CLR type on different context instances"); Assert.True( blog1PairForBlogType.Equals(entitySetMappingCache1Bis[new Blog().GetType()]), "Metadata workspace should produce the same entity set for the same CLR type using different instances of the same type"); } }
public void GetEntitySetMappingCache_produces_multiple_entitysets_for_single_clr_type_present_in_multiple_models() { var blogType = typeof(Blog); Internal.EntitySetTypePair blog1PairForBlogType; using (var blog1 = new BlogDbContext()) { using (var blog2 = new BlogDbContextVersion2()) { //obtain the type to entityset dictionaries and update the mappings var workspace1 = ((IObjectContextAdapter)blog1).ObjectContext.MetadataWorkspace.MetadataOptimization; var entitySetMappingCache1 = workspace1.EntitySetMappingCache; workspace1.TryUpdateEntitySetMappingsForType(blogType); var workspace2 = ((IObjectContextAdapter)blog2).ObjectContext.MetadataWorkspace.MetadataOptimization; var entitySetMappingCache2 = workspace2.EntitySetMappingCache; workspace2.TryUpdateEntitySetMappingsForType(blogType); //check that the same clr type maps to different entity sets on different metadata workspaces blog1PairForBlogType = entitySetMappingCache1[blogType]; Assert.NotNull(blog1PairForBlogType); Assert.False( ReferenceEquals(blog1PairForBlogType, entitySetMappingCache2[blogType]), "Single CLR type on two different metadata workspaces erroneously maps to the same entity set instance"); } } using (var blog1Bis = new BlogDbContext()) { var workspace1Bis = ((IObjectContextAdapter)blog1Bis).ObjectContext.MetadataWorkspace.MetadataOptimization; var entitySetMappingCache1Bis = workspace1Bis.EntitySetMappingCache; workspace1Bis.TryUpdateEntitySetMappingsForType(blogType); Assert.True( blog1PairForBlogType.Equals(entitySetMappingCache1Bis[blogType]), "Metadata workspace should produce same entity set for same CLR type on different context instances"); Assert.True( blog1PairForBlogType.Equals(entitySetMappingCache1Bis[new Blog().GetType()]), "Metadata workspace should produce the same entity set for the same CLR type using different instances of the same type"); } }