public void Configure_mapping_can_process_entity_splitting() { EdmModel model = new TestModelBuilder() .Entity("E") .Key("P1") .Property("P2") .Property("P3") .Property("P4") .Property("P5"); var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(model); var entityType = model.GetEntityType("E"); var modelConfiguration = new ModelConfiguration(); var entityMappingConfiguration1 = new EntityMappingConfiguration { Properties = new List<PropertyPath> { new PropertyPath(entityType.GetDeclaredPrimitiveProperty("P1").GetClrPropertyInfo()), new PropertyPath(entityType.GetDeclaredPrimitiveProperty("P2").GetClrPropertyInfo()), new PropertyPath(entityType.GetDeclaredPrimitiveProperty("P3").GetClrPropertyInfo()) }, TableName = new DatabaseName("E1") }; var entityMappingConfiguration2 = new EntityMappingConfiguration { Properties = new List<PropertyPath> { new PropertyPath(entityType.GetDeclaredPrimitiveProperty("P1").GetClrPropertyInfo()), new PropertyPath(entityType.GetDeclaredPrimitiveProperty("P4").GetClrPropertyInfo()), new PropertyPath(entityType.GetDeclaredPrimitiveProperty("P5").GetClrPropertyInfo()) }, TableName = new DatabaseName("E2") }; var entityConfiguration = modelConfiguration.Entity(entityType.GetClrType()); entityConfiguration.AddMappingConfiguration(entityMappingConfiguration1); entityConfiguration.AddMappingConfiguration(entityMappingConfiguration2); modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest); var entityTypeMapping = databaseMapping.GetEntityTypeMapping(entityType); var table1 = entityTypeMapping.TypeMappingFragments[0].Table; var table2 = entityTypeMapping.TypeMappingFragments[1].Table; Assert.NotSame(table1, table2); Assert.Equal("E1", table1.GetTableName().Name); Assert.Equal("E2", table2.GetTableName().Name); Assert.Equal(3, table1.Columns.Count); Assert.Equal(3, table2.Columns.Count); Assert.Equal(2, entityTypeMapping.TypeMappingFragments.Count); var entityTypeMappingFragment1 = entityTypeMapping.TypeMappingFragments[0]; var entityTypeMappingFragment2 = entityTypeMapping.TypeMappingFragments[1]; Assert.Equal(3, entityTypeMappingFragment1.PropertyMappings.Count); Assert.Equal("P1", entityTypeMappingFragment1.PropertyMappings[0].Column.Name); Assert.Equal("P2", entityTypeMappingFragment1.PropertyMappings[1].Column.Name); Assert.Equal("P3", entityTypeMappingFragment1.PropertyMappings[2].Column.Name); Assert.Equal(3, entityTypeMappingFragment2.PropertyMappings.Count); Assert.Equal("P1", entityTypeMappingFragment2.PropertyMappings[0].Column.Name); Assert.Equal("P4", entityTypeMappingFragment2.PropertyMappings[1].Column.Name); Assert.Equal("P5", entityTypeMappingFragment2.PropertyMappings[2].Column.Name); }
public void Configure_entity_splitting_should_throw_if_ignored_property_is_mapped() { EdmModel model = new TestModelBuilder() .Entity("E") .Key("P1"); var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(model); var entityType = model.GetEntityType("E"); var modelConfiguration = new ModelConfiguration(); var entityConfiguration = modelConfiguration.Entity(entityType.GetClrType()); var p1PropertyInfo = entityType.GetDeclaredPrimitiveProperty("P1").GetClrPropertyInfo(); var entityMappingConfiguration1 = new EntityMappingConfiguration { Properties = new List<PropertyPath> { new PropertyPath(p1PropertyInfo), new PropertyPath(new MockPropertyInfo(typeof(int), "P2")) }, TableName = new DatabaseName("E") }; entityConfiguration.AddMappingConfiguration(entityMappingConfiguration1); Assert.Equal( Strings.EntityMappingConfiguration_CannotMapIgnoredProperty("E", "P2"), Assert.Throws<InvalidOperationException>( () => modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest)).Message); }