本文整理汇总了C#中System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure方法的典型用法代码示例。如果您正苦于以下问题:C# ModelConfiguration.Configure方法的具体用法?C# ModelConfiguration.Configure怎么用?C# ModelConfiguration.Configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration
的用法示例。
在下文中一共展示了ModelConfiguration.Configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure_should_uniquify_unconfigured_function_names
public void Configure_should_uniquify_unconfigured_function_names()
{
var modelConfiguration = new ModelConfiguration();
var typeA = new MockType("A");
var typeB = new MockType("B");
modelConfiguration.Entity(typeA).MapToStoredProcedures();
var modificationFunctionsConfiguration
= new ModificationStoredProceduresConfiguration();
var modificationFunctionConfiguration = new ModificationStoredProcedureConfiguration();
modificationFunctionConfiguration.HasName("A_Insert");
modificationFunctionsConfiguration.Insert(modificationFunctionConfiguration);
modelConfiguration.Entity(typeB).MapToStoredProcedures(modificationFunctionsConfiguration, true);
var model = new EdmModel(DataSpace.CSpace);
var entityA = model.AddEntityType("A");
entityA.GetMetadataProperties().SetClrType(typeA);
entityA.SetConfiguration(modelConfiguration.Entity(typeA));
var entityB = model.AddEntityType("B");
entityB.GetMetadataProperties().SetClrType(typeB);
entityB.SetConfiguration(modelConfiguration.Entity(typeB));
model.AddEntitySet("AS", entityA);
model.AddEntitySet("BS", entityB);
var databaseMapping
= new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest)
.Generate(model);
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
Assert.True(databaseMapping.Database.Functions.Any(f => f.StoreFunctionNameAttribute == "A_Insert"));
Assert.True(databaseMapping.Database.Functions.Any(f => f.StoreFunctionNameAttribute == "A_Insert1"));
}
示例2: Configure_mapping_can_process_one_level_TPC_on_both_sides_of_tree
public void Configure_mapping_can_process_one_level_TPC_on_both_sides_of_tree()
{
//Setup
var model = TestModelBuilderHelpers.CreateSingleLevelInheritanceWithThreeEntities();
var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest).Generate(model);
var entityType1 = model.GetEntityType("E1");
var entityType2 = model.GetEntityType("E2");
var entityType3 = model.GetEntityType("E3");
// Action
var modelConfiguration = new ModelConfiguration();
modelConfiguration.Entity(entityType2.GetClrType())
.AddMappingConfiguration(
new EntityMappingConfiguration
{
MapInheritedProperties = true,
TableName = new DatabaseName("E2")
});
modelConfiguration.Entity(entityType3.GetClrType())
.AddMappingConfiguration(
new EntityMappingConfiguration
{
MapInheritedProperties = true,
TableName = new DatabaseName("E3")
});
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
//Validate
var entitySetMapping = databaseMapping.GetEntitySetMapping(model.GetEntitySet(entityType1));
Assert.NotNull(entitySetMapping);
Assert.Equal(3, entitySetMapping.EntityTypeMappings.Count());
var entityType1Mapping = databaseMapping.GetEntityTypeMapping(entityType1);
var entityType2Mapping = databaseMapping.GetEntityTypeMapping(entityType2);
var entityType3Mapping = databaseMapping.GetEntityTypeMapping(entityType3);
var table1 = entityType1Mapping.MappingFragments.Single().Table;
var table2 = entityType2Mapping.MappingFragments.Single().Table;
var table3 = entityType3Mapping.MappingFragments.Single().Table;
Assert.False(entityType1Mapping.IsHierarchyMapping);
Assert.Equal(2, table1.Properties.Count);
Assert.Equal("P1", table1.Properties[0].Name);
Assert.Equal("P2", table1.Properties[1].Name);
Assert.Equal(2, entityType1Mapping.MappingFragments.Single().ColumnMappings.Count());
Assert.Same(entityType1Mapping.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty, table1.Properties[0]);
Assert.Same(entityType1Mapping.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty, table1.Properties[1]);
Assert.False(entityType2Mapping.IsHierarchyMapping);
Assert.Equal("E2", table2.Name);
Assert.Equal(3, table2.Properties.Count);
Assert.Equal("P1", table2.Properties[0].Name);
Assert.Equal("P2", table2.Properties[1].Name);
Assert.Equal("P3", table2.Properties[2].Name);
Assert.NotSame(table1, table2);
Assert.NotSame(table1.Properties[0], table2.Properties[0]);
Assert.NotSame(table1.Properties[1], table2.Properties[1]);
Assert.Equal(3, entityType2Mapping.MappingFragments.Single().ColumnMappings.Count());
Assert.Same(entityType2Mapping.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty, table2.Properties[0]);
Assert.Same(entityType2Mapping.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty, table2.Properties[1]);
Assert.Same(entityType2Mapping.MappingFragments.Single().ColumnMappings.ElementAt(2).ColumnProperty, table2.Properties[2]);
Assert.False(entityType3Mapping.IsHierarchyMapping);
Assert.Equal("E3", table3.Name);
Assert.Equal(3, table3.Properties.Count);
Assert.Equal("P1", table3.Properties[0].Name);
Assert.Equal("P2", table3.Properties[1].Name);
Assert.Equal("P4", table3.Properties[2].Name);
Assert.NotSame(table1, table3);
Assert.NotSame(table3, table2);
Assert.NotSame(table1.Properties[0], table3.Properties[0]);
Assert.NotSame(table1.Properties[1], table3.Properties[1]);
Assert.Equal(3, entityType3Mapping.MappingFragments.Single().ColumnMappings.Count());
Assert.Same(entityType3Mapping.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty, table3.Properties[0]);
Assert.Same(entityType3Mapping.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty, table3.Properties[1]);
Assert.Same(entityType3Mapping.MappingFragments.Single().ColumnMappings.ElementAt(2).ColumnProperty, table3.Properties[2]);
}
示例3: Configure_should_uniquify_unconfigured_association_function_names
public void Configure_should_uniquify_unconfigured_association_function_names()
{
var mockPropertyInfo = typeof(BType1).GetDeclaredProperty("As");
var modelConfiguration = new ModelConfiguration();
var navigationPropertyConfiguration
= modelConfiguration.Entity(typeof(BType1)).Navigation(mockPropertyInfo);
navigationPropertyConfiguration.ModificationStoredProceduresConfiguration
= new ModificationStoredProceduresConfiguration();
var modificationFunctionConfiguration = new ModificationStoredProcedureConfiguration();
modificationFunctionConfiguration.HasName("AB_Delete");
navigationPropertyConfiguration.ModificationStoredProceduresConfiguration
.Insert(modificationFunctionConfiguration);
var model = new EdmModel(DataSpace.CSpace);
var entityA = model.AddEntityType("A");
entityA.GetMetadataProperties().SetClrType(typeof(AType1));
entityA.SetConfiguration(modelConfiguration.Entity(typeof(AType1)));
var entityB = model.AddEntityType("B");
entityB.GetMetadataProperties().SetClrType(typeof(BType1));
entityB.SetConfiguration(modelConfiguration.Entity(typeof(BType1)));
model.AddEntitySet("AS", entityA);
model.AddEntitySet("BS", entityB);
var associationType
= model.AddAssociationType(
"M2M",
entityA,
RelationshipMultiplicity.Many,
entityB,
RelationshipMultiplicity.Many);
associationType.SetConfiguration(navigationPropertyConfiguration);
var navigationProperty
= entityB.AddNavigationProperty("As", associationType);
navigationProperty.SetClrPropertyInfo(mockPropertyInfo);
model.AddAssociationSet("M2MSet", associationType);
var databaseMapping
= new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest)
.Generate(model);
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
Assert.True(databaseMapping.Database.Functions.Any(f => f.StoreFunctionNameAttribute == "AB_Delete"));
Assert.True(databaseMapping.Database.Functions.Any(f => f.StoreFunctionNameAttribute == "AB_Delete1"));
}
示例4: Configure_mapping_can_configure_one_level_TPT_on_both_sides_of_tree
public void Configure_mapping_can_configure_one_level_TPT_on_both_sides_of_tree()
{
//Setup
var model = TestModelBuilderHelpers.CreateSingleLevelInheritanceWithThreeEntities();
var entityType1 = model.GetEntityType("E1");
var entityType2 = model.GetEntityType("E2");
var entityType3 = model.GetEntityType("E3");
(entityType1.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1")).SetStoreGeneratedPattern(
StoreGeneratedPattern.Identity);
var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest).Generate(model);
var modelConfiguration = new ModelConfiguration();
modelConfiguration.Entity(entityType2.GetClrType()).ToTable("E2");
modelConfiguration.Entity(entityType3.GetClrType()).ToTable("E3");
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
var entityTypeMapping1 = databaseMapping.GetEntityTypeMapping(entityType1);
var entityTypeMapping2 = databaseMapping.GetEntityTypeMapping(entityType2);
var entityTypeMapping3 = databaseMapping.GetEntityTypeMapping(entityType3);
var table1 = entityTypeMapping1.MappingFragments.Single().Table;
var table2 = entityTypeMapping2.MappingFragments.Single().Table;
var table3 = entityTypeMapping3.MappingFragments.Single().Table;
Assert.NotSame(table1, table2);
Assert.NotSame(table1, table3);
Assert.NotSame(table3, table2);
Assert.True(entityTypeMapping1.IsHierarchyMapping);
Assert.Equal(2, table1.Properties.Count);
Assert.Equal("P1", table1.Properties[0].Name);
Assert.Equal(StoreGeneratedPattern.Identity, table1.Properties[0].StoreGeneratedPattern);
Assert.Equal("P2", table1.Properties[1].Name);
Assert.Equal(2, entityTypeMapping1.MappingFragments.Single().ColumnMappings.Count());
Assert.Equal("P1", entityTypeMapping1.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty.Name);
Assert.Equal("P2", entityTypeMapping1.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty.Name);
Assert.False(entityTypeMapping2.IsHierarchyMapping);
Assert.Equal(2, entityTypeMapping2.MappingFragments.Single().ColumnMappings.Count());
Assert.Equal("P1", entityTypeMapping2.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty.Name);
Assert.Equal(StoreGeneratedPattern.None, table2.Properties[0].StoreGeneratedPattern);
Assert.Equal("P3", entityTypeMapping2.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty.Name);
Assert.Equal(2, table2.Properties.Count);
Assert.Equal("P1", table2.Properties[0].Name);
Assert.Equal("P3", table2.Properties[1].Name);
Assert.NotSame(table1.Properties[0], table2.Properties[0]);
Assert.False(entityTypeMapping3.IsHierarchyMapping);
Assert.Equal(2, entityTypeMapping3.MappingFragments.Single().ColumnMappings.Count());
Assert.Equal(StoreGeneratedPattern.None, table3.Properties[0].StoreGeneratedPattern);
Assert.Equal("P1", entityTypeMapping3.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty.Name);
Assert.Equal("P4", entityTypeMapping3.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty.Name);
Assert.Equal(2, table3.Properties.Count);
Assert.Equal("P1", table3.Properties[0].Name);
Assert.Equal("P4", table3.Properties[1].Name);
Assert.NotSame(table1.Properties[0], table3.Properties[0]);
Assert.NotSame(table2.Properties[0], table3.Properties[0]);
}
示例5: Configure_should_configure_active_entities_and_complex_types
public void Configure_should_configure_active_entities_and_complex_types()
{
var mockEntityType = new MockType();
var mockComplexType = new MockType();
var model = new EdmModel(DataSpace.CSpace);
var entityType = model.AddEntityType("E");
entityType.GetMetadataProperties().SetClrType(mockEntityType);
var complexType = model.AddComplexType("C");
complexType.GetMetadataProperties().SetClrType(mockComplexType);
var modelConfiguration = new ModelConfiguration();
var mockComplexTypeConfiguration = new Mock<ComplexTypeConfiguration>(mockComplexType.Object);
var mockEntityTypeConfiguration = new Mock<EntityTypeConfiguration>(mockEntityType.Object);
modelConfiguration.Add(mockComplexTypeConfiguration.Object);
modelConfiguration.Add(mockEntityTypeConfiguration.Object);
modelConfiguration.Configure(model);
mockComplexTypeConfiguration.Verify(c => c.Configure(complexType));
mockEntityTypeConfiguration.Verify(c => c.Configure(entityType, model));
}
示例6: Configure_should_configure_default_schema
public void Configure_should_configure_default_schema()
{
var modelConfiguration
= new ModelConfiguration
{
DefaultSchema = "foo"
};
var databaseMetadata = new EdmModel(DataSpace.CSpace);
databaseMetadata.AddEntitySet("ES", new EntityType("E", "N", DataSpace.CSpace));
var databaseMapping
= new DbDatabaseMapping().Initialize(
new EdmModel(DataSpace.CSpace),
databaseMetadata);
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
Assert.Equal("foo", databaseMapping.Database.GetEntitySets().Single().Schema);
}
示例7: Configure_should_configure_default_schema_on_functions
public void Configure_should_configure_default_schema_on_functions()
{
var modelConfiguration
= new ModelConfiguration
{
DefaultSchema = "foo"
};
var databaseMetadata = new EdmModel(DataSpace.SSpace);
databaseMetadata.AddFunction("F", new EdmFunctionPayload());
var databaseMapping
= new DbDatabaseMapping().Initialize(
new EdmModel(DataSpace.CSpace),
databaseMetadata);
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
Assert.Equal("foo", databaseMapping.Database.Functions.Single().Schema);
}
示例8: Configure_should_not_throw_when_only_derived_type_mapped_to_function_but_base_is_abstract
public void Configure_should_not_throw_when_only_derived_type_mapped_to_function_but_base_is_abstract()
{
var modelConfiguration = new ModelConfiguration();
var baseType = new MockType("B");
var derivedType = new MockType("D").BaseType(baseType);
modelConfiguration.Entity(baseType);
modelConfiguration.Entity(derivedType).MapToStoredProcedures();
var model = new EdmModel(DataSpace.CSpace);
var baseEntity = model.AddEntityType("Base");
baseEntity.Annotations.SetClrType(baseType);
baseEntity.Abstract = true;
var derivedEntity = model.AddEntityType("Derived");
derivedEntity.Annotations.SetClrType(derivedType);
derivedEntity.BaseType = baseEntity;
modelConfiguration.Configure(model);
Assert.True(modelConfiguration.Entity(baseType).IsMappedToFunctions);
Assert.True(modelConfiguration.Entity(derivedType).IsMappedToFunctions);
}
示例9: Configure_should_not_throw_when_only_derived_type_mapped_to_function_but_base_is_abstract
public void Configure_should_not_throw_when_only_derived_type_mapped_to_function_but_base_is_abstract()
{
var modelConfiguration = new ModelConfiguration();
modelConfiguration.Entity(typeof(BType2));
modelConfiguration.Entity(typeof(CType2)).MapToStoredProcedures();
var model = new EdmModel(DataSpace.CSpace);
var baseEntity = model.AddEntityType("Base");
baseEntity.GetMetadataProperties().SetClrType(typeof(BType2));
baseEntity.Abstract = true;
var derivedEntity = model.AddEntityType("Derived");
derivedEntity.GetMetadataProperties().SetClrType(typeof(CType2));
derivedEntity.BaseType = baseEntity;
modelConfiguration.Configure(model);
Assert.NotNull(modelConfiguration.Entity(typeof(BType2)).ModificationStoredProceduresConfiguration);
Assert.NotNull(modelConfiguration.Entity(typeof(CType2)).ModificationStoredProceduresConfiguration);
}
示例10: Configure_should_throw_when_only_derived_type_mapped_to_functions
public void Configure_should_throw_when_only_derived_type_mapped_to_functions()
{
var modelConfiguration = new ModelConfiguration();
modelConfiguration.Entity(typeof(BType2));
modelConfiguration.Entity(typeof(AType2)).MapToStoredProcedures();
var model = new EdmModel(DataSpace.CSpace);
var baseEntity = model.AddEntityType("Base");
baseEntity.GetMetadataProperties().SetClrType(typeof(BType2));
var derivedEntity = model.AddEntityType("Derived");
derivedEntity.GetMetadataProperties().SetClrType(typeof(AType2));
derivedEntity.BaseType = baseEntity;
Assert.Equal(
Strings.BaseTypeNotMappedToFunctions("BType2", "AType2"),
Assert.Throws<InvalidOperationException>(
() => modelConfiguration.Configure(model)).Message);
}
示例11: Configure_entity_splitting_should_throw_if_ignored_property_is_mapped
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_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest).Generate(model);
var entityType = model.GetEntityType("E");
var modelConfiguration = new ModelConfiguration();
var entityConfiguration = modelConfiguration.Entity(entityType.GetClrType());
var p1PropertyInfo = entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "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);
}
示例12: Configure_when_base_entity_mapped_to_function_should_map_sub_types_to_functions
public void Configure_when_base_entity_mapped_to_function_should_map_sub_types_to_functions()
{
var modelConfiguration = new ModelConfiguration();
modelConfiguration.Entity(typeof(CType2)).MapToStoredProcedures();
modelConfiguration.Entity(typeof(BType2));
modelConfiguration.Entity(typeof(AType2));
var model = new EdmModel(DataSpace.CSpace);
var rootEntity = model.AddEntityType("Root");
rootEntity.GetMetadataProperties().SetClrType(typeof(CType2));
var middleEntity = model.AddEntityType("Middle");
middleEntity.GetMetadataProperties().SetClrType(typeof(BType2));
middleEntity.BaseType = rootEntity;
var leafEntity = model.AddEntityType("Leaf");
leafEntity.GetMetadataProperties().SetClrType(typeof(AType2));
leafEntity.BaseType = middleEntity;
modelConfiguration.Configure(model);
Assert.NotNull(modelConfiguration.Entity(typeof(CType2)).ModificationStoredProceduresConfiguration);
Assert.NotNull(modelConfiguration.Entity(typeof(BType2)).ModificationStoredProceduresConfiguration);
Assert.NotNull(modelConfiguration.Entity(typeof(AType2)).ModificationStoredProceduresConfiguration);
}
示例13: Configure_mapping_can_process_entity_splitting
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_ProviderInfo, 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.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1").GetClrPropertyInfo(
)),
new PropertyPath(
entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P2").GetClrPropertyInfo(
)),
new PropertyPath(
entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P3").GetClrPropertyInfo(
))
},
TableName = new DatabaseName("E1")
};
var entityMappingConfiguration2 =
new EntityMappingConfiguration
{
Properties =
new List<PropertyPath>
{
new PropertyPath(
entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1").GetClrPropertyInfo(
)),
new PropertyPath(
entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P4").GetClrPropertyInfo(
)),
new PropertyPath(
entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "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.MappingFragments[0].Table;
var table2 = entityTypeMapping.MappingFragments[1].Table;
Assert.NotSame(table1, table2);
Assert.Equal("E1", table1.GetTableName().Name);
Assert.Equal("E2", table2.GetTableName().Name);
Assert.Equal(3, table1.Properties.Count);
Assert.Equal(3, table2.Properties.Count);
Assert.Equal(2, entityTypeMapping.MappingFragments.Count);
var entityTypeMappingFragment1 = entityTypeMapping.MappingFragments[0];
var entityTypeMappingFragment2 = entityTypeMapping.MappingFragments[1];
Assert.Equal(3, entityTypeMappingFragment1.ColumnMappings.Count());
Assert.Equal("P1", entityTypeMappingFragment1.ColumnMappings.ElementAt(0).ColumnProperty.Name);
Assert.Equal("P2", entityTypeMappingFragment1.ColumnMappings.ElementAt(1).ColumnProperty.Name);
Assert.Equal("P3", entityTypeMappingFragment1.ColumnMappings.ElementAt(2).ColumnProperty.Name);
Assert.Equal(3, entityTypeMappingFragment2.ColumnMappings.Count());
Assert.Equal("P1", entityTypeMappingFragment2.ColumnMappings.ElementAt(0).ColumnProperty.Name);
Assert.Equal("P4", entityTypeMappingFragment2.ColumnMappings.ElementAt(1).ColumnProperty.Name);
Assert.Equal("P5", entityTypeMappingFragment2.ColumnMappings.ElementAt(2).ColumnProperty.Name);
}
示例14: Configure_mapping_can_process_one_level_TPH_on_both_sides_of_tree
public void Configure_mapping_can_process_one_level_TPH_on_both_sides_of_tree()
{
//Setup
var model = TestModelBuilderHelpers.CreateSingleLevelInheritanceWithThreeEntities();
var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest).Generate(model);
var entityType1 = model.GetEntityType("E1");
var entityType2 = model.GetEntityType("E2");
var entityType3 = model.GetEntityType("E3");
// Action
var modelConfiguration = new ModelConfiguration();
var entity1Configuration = modelConfiguration.Entity(entityType1.GetClrType());
var entity1MappingConfiguration =
new EntityMappingConfiguration
{
TableName = new DatabaseName("E1")
};
entity1MappingConfiguration
.AddValueCondition(
new ValueConditionConfiguration(entity1MappingConfiguration, "P3")
{
Value = null
});
entity1MappingConfiguration
.AddValueCondition(
new ValueConditionConfiguration(entity1MappingConfiguration, "P4")
{
Value = null
});
entity1Configuration.AddMappingConfiguration(entity1MappingConfiguration);
var entity1SubTypeMappingConfiguration =
new EntityMappingConfiguration
{
TableName = new DatabaseName("E1")
};
entity1SubTypeMappingConfiguration
.AddValueCondition(
new ValueConditionConfiguration(entity1SubTypeMappingConfiguration, "P3")
{
Value = null
});
entity1SubTypeMappingConfiguration
.AddNullabilityCondition(
new NotNullConditionConfiguration(
entity1SubTypeMappingConfiguration,
new PropertyPath(
entityType3.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P4").GetClrPropertyInfo())));
entity1Configuration.AddSubTypeMappingConfiguration(entityType3.GetClrType(), entity1SubTypeMappingConfiguration);
var entity2Configuration = modelConfiguration.Entity(entityType2.GetClrType());
var entity2MappingConfiguration =
new EntityMappingConfiguration
{
TableName = new DatabaseName("E1")
};
entity2MappingConfiguration
.AddNullabilityCondition(
new NotNullConditionConfiguration(
entity2MappingConfiguration,
new PropertyPath(
entityType2.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P3").GetClrPropertyInfo())));
entity2MappingConfiguration
.AddValueCondition(
new ValueConditionConfiguration(entity2MappingConfiguration, "P4")
{
Value = null
});
entity2Configuration.AddMappingConfiguration(entity2MappingConfiguration);
modelConfiguration.NormalizeConfigurations();
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
//Validate
var entitySetMapping = databaseMapping.GetEntitySetMapping(model.GetEntitySet(entityType1));
Assert.NotNull(entitySetMapping);
Assert.Equal(4, entitySetMapping.EntityTypeMappings.Count());
var entityType1Mapping = databaseMapping.GetEntityTypeMapping(entityType1);
var entityType1MappingConditions = databaseMapping.GetEntityTypeMappings(entityType1).Single(x => !x.IsHierarchyMapping);
var entityType2Mapping = databaseMapping.GetEntityTypeMapping(entityType2);
var entityType3Mapping = databaseMapping.GetEntityTypeMapping(entityType3);
var table1 = entityType1Mapping.MappingFragments.Single().Table;
var table2 = entityType2Mapping.MappingFragments.Single().Table;
var table3 = entityType3Mapping.MappingFragments.Single().Table;
Assert.True(entityType1Mapping.IsHierarchyMapping);
Assert.Equal(4, table1.Properties.Count);
Assert.Equal("P1", table1.Properties[0].Name);
Assert.Equal("P2", table1.Properties[1].Name);
Assert.Equal("P3", table1.Properties[2].Name);
Assert.Equal("P4", table1.Properties[3].Name);
Assert.Equal(2, entityType1Mapping.MappingFragments.Single().ColumnMappings.Count());
Assert.Equal("P1", entityType1Mapping.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty.Name);
Assert.Equal("P2", entityType1Mapping.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty.Name);
Assert.Same(
table1.Properties[2], entityType1MappingConditions.MappingFragments.Single().ColumnConditions.ElementAt(0).Column);
Assert.True((bool)entityType1MappingConditions.MappingFragments.Single().ColumnConditions.ElementAt(0).IsNull);
Assert.Same(
table1.Properties[3], entityType1MappingConditions.MappingFragments.Single().ColumnConditions.ElementAt(1).Column);
Assert.True((bool)entityType1MappingConditions.MappingFragments.Single().ColumnConditions.ElementAt(1).IsNull);
//.........这里部分代码省略.........
示例15: Configure_should_uniquify_unconfigured_assocation_function_names
public void Configure_should_uniquify_unconfigured_assocation_function_names()
{
var typeA = new MockType("A");
var typeB = new MockType("B").Property(typeA.AsCollection(), "As");
var mockPropertyInfo = typeB.GetProperty("As");
typeA.Property(typeB.AsCollection(), "Bs");
var modelConfiguration = new ModelConfiguration();
var navigationPropertyConfiguration
= modelConfiguration.Entity(typeB).Navigation(mockPropertyInfo);
navigationPropertyConfiguration.ModificationFunctionsConfiguration
= new ModificationFunctionsConfiguration();
var modificationFunctionConfiguration = new ModificationFunctionConfiguration();
modificationFunctionConfiguration.HasName("M2M_Delete");
navigationPropertyConfiguration.ModificationFunctionsConfiguration
.Insert(modificationFunctionConfiguration);
var model = new EdmModel(DataSpace.CSpace);
var entityA = model.AddEntityType("A");
entityA.Annotations.SetClrType(typeA);
entityA.SetConfiguration(modelConfiguration.Entity(typeA));
var entityB = model.AddEntityType("B");
entityB.Annotations.SetClrType(typeB);
entityB.SetConfiguration(modelConfiguration.Entity(typeB));
model.AddEntitySet("AS", entityA);
model.AddEntitySet("BS", entityB);
var associationType
= model.AddAssociationType(
"M2M",
entityA,
RelationshipMultiplicity.Many,
entityB,
RelationshipMultiplicity.Many);
associationType.SetConfiguration(navigationPropertyConfiguration);
var navigationProperty
= entityB.AddNavigationProperty("As", associationType);
navigationProperty.SetClrPropertyInfo(mockPropertyInfo);
model.AddAssociationSet("M2MSet", associationType);
var databaseMapping
= new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest)
.Generate(model);
modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);
Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete"));
Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete1"));
}