本文整理汇总了C#中System.Data.Entity.Edm.EdmModel类的典型用法代码示例。如果您正苦于以下问题:C# EdmModel类的具体用法?C# EdmModel怎么用?C# EdmModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EdmModel类属于System.Data.Entity.Edm命名空间,在下文中一共展示了EdmModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure_should_configure_inverse
public void Configure_should_configure_inverse()
{
var inverseMockPropertyInfo = new MockPropertyInfo();
var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo())
{
InverseNavigationProperty = inverseMockPropertyInfo
};
var associationType = new EdmAssociationType().Initialize();
var inverseAssociationType = new EdmAssociationType().Initialize();
var model = new EdmModel().Initialize();
model.AddAssociationType(inverseAssociationType);
var inverseNavigationProperty
= model.AddEntityType("T")
.AddNavigationProperty("N", inverseAssociationType);
inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);
navigationPropertyConfiguration.Configure(
new EdmNavigationProperty
{
Association = associationType
}, model, new EntityTypeConfiguration(typeof(object)));
Assert.Same(associationType, inverseNavigationProperty.Association);
Assert.Same(associationType.SourceEnd, inverseNavigationProperty.ResultEnd);
Assert.Equal(0, model.GetAssociationTypes().Count());
}
示例2: MapComplexType_should_not_map_invalid_structural_type
public void MapComplexType_should_not_map_invalid_structural_type()
{
var model = new EdmModel().Initialize();
var typeMapper = new TypeMapper(new MappingContext(new ModelConfiguration(), new ConventionsConfiguration(), model));
Assert.Null(typeMapper.MapComplexType(typeof(string)));
}
示例3: Generate_should_correctly_map_string_primitive_property_facets
public void Generate_should_correctly_map_string_primitive_property_facets()
{
var model = new EdmModel().Initialize();
var entityType = model.AddEntityType("E");
entityType.SetClrType(typeof(object));
model.AddEntitySet("ESet", entityType);
var property = entityType.AddPrimitiveProperty("P");
property.PropertyType.EdmType = EdmPrimitiveType.String;
property.PropertyType.IsNullable = false;
property.PropertyType.PrimitiveTypeFacets.IsFixedLength = true;
property.PropertyType.PrimitiveTypeFacets.IsMaxLength = true;
property.PropertyType.PrimitiveTypeFacets.IsUnicode = true;
property.PropertyType.PrimitiveTypeFacets.MaxLength = 42;
property.PropertyType.PrimitiveTypeFacets.Precision = 23;
property.PropertyType.PrimitiveTypeFacets.Scale = 77;
property.SetStoreGeneratedPattern(DbStoreGeneratedPattern.Identity);
var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(model);
var column = databaseMapping.GetEntityTypeMapping(entityType).TypeMappingFragments.Single().PropertyMappings.Single().Column;
Assert.False(column.IsNullable);
Assert.Null(column.Facets.IsFixedLength);
Assert.Equal(true, column.Facets.IsMaxLength);
Assert.Null(column.Facets.IsUnicode);
Assert.Equal(42, column.Facets.MaxLength);
Assert.Null(column.Facets.Precision);
Assert.Null(column.Facets.Scale);
Assert.Equal(DbStoreGeneratedPattern.Identity, column.StoreGeneratedPattern);
}
示例4: GetClrTypes_should_return_ospace_types
public void GetClrTypes_should_return_ospace_types()
{
var model = new EdmModel().Initialize();
model.AddEntityType("A").SetClrType(typeof(object));
model.AddEntityType("B").SetClrType(typeof(string));
Assert.Equal(2, model.GetClrTypes().Count());
}
示例5: Can_get_and_set_provider_info_annotation
public void Can_get_and_set_provider_info_annotation()
{
var model = new EdmModel();
var providerInfo = ProviderRegistry.Sql2008_ProviderInfo;
model.SetProviderInfo(providerInfo);
Assert.Same(providerInfo, model.GetProviderInfo());
}
示例6: Apply_should_ignore_current_entity_set
public void Apply_should_ignore_current_entity_set()
{
var model = new EdmModel().Initialize();
var entitySet = model.AddEntitySet("Cats", new EdmEntityType());
((IEdmConvention<EdmEntitySet>)new PluralizingEntitySetNameConvention())
.Apply(entitySet, model);
Assert.Equal("Cats", entitySet.Name);
}
示例7: ApplyModel_should_run_model_conventions
public void ApplyModel_should_run_model_conventions()
{
var model = new EdmModel().Initialize();
var mockConvention = new Mock<IEdmConvention>();
var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
conventionsConfiguration.ApplyModel(model);
mockConvention.Verify(c => c.Apply(model), Times.AtMostOnce());
}
示例8: Generate_should_initialize_mapping_model
public void Generate_should_initialize_mapping_model()
{
var model = new EdmModel().Initialize();
var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(model);
Assert.NotNull(databaseMapping);
Assert.NotNull(databaseMapping.Database);
Assert.Same(model.Containers.Single(), databaseMapping.EntityContainerMappings.Single().EntityContainer);
}
示例9: InitializeDatabaseMapping
private static DbDatabaseMapping InitializeDatabaseMapping(EdmModel model)
{
//Contract.Requires(model != null);
var databaseMapping = new DbDatabaseMapping().Initialize(
model, new DbDatabaseMetadata().Initialize(model.Version));
databaseMapping.EntityContainerMappings.Single().EntityContainer = model.Containers.Single();
return databaseMapping;
}
示例10: FixNavigationProperties
private static void FixNavigationProperties(
EdmModel model, EdmAssociationType unifiedAssociation, EdmAssociationType redundantAssociation)
{
foreach (var navigationProperty
in model.GetEntityTypes()
.SelectMany(e => e.NavigationProperties)
.Where(np => np.Association == redundantAssociation))
{
navigationProperty.Association = unifiedAssociation;
navigationProperty.ResultEnd = unifiedAssociation.SourceEnd;
}
}
示例11: Generate
public DbDatabaseMapping Generate(EdmModel model)
{
//Contract.Requires(model != null);
var databaseMapping = InitializeDatabaseMapping(model);
GenerateEntityTypes(model, databaseMapping);
GenerateDiscriminators(databaseMapping);
GenerateAssociationTypes(model, databaseMapping);
return databaseMapping;
}
示例12: MapComplexType_should_not_map_ignored_type
public void MapComplexType_should_not_map_ignored_type()
{
var model = new EdmModel().Initialize();
var mockModelConfiguration = new Mock<ModelConfiguration>();
var typeMapper = new TypeMapper(new MappingContext(mockModelConfiguration.Object, new ConventionsConfiguration(), model));
var mockType = new MockType("Foo");
mockModelConfiguration.Setup(m => m.IsIgnoredType(mockType)).Returns(true);
var complexType = typeMapper.MapComplexType(mockType);
Assert.Null(complexType);
}
示例13: HasCascadeDeletePath_should_return_true_for_self_ref_cascade
public void HasCascadeDeletePath_should_return_true_for_self_ref_cascade()
{
var model = new EdmModel().Initialize();
var entityType = model.AddEntityType("A");
var associationType = new EdmAssociationType().Initialize();
associationType.SourceEnd.EntityType
= associationType.TargetEnd.EntityType
= entityType;
associationType.SourceEnd.DeleteAction = EdmOperationAction.Cascade;
model.AddAssociationType(associationType);
Assert.True(model.HasCascadeDeletePath(entityType, entityType));
}
示例14: Map_should_not_detect_arrays_as_collection_associations
public void Map_should_not_detect_arrays_as_collection_associations()
{
var modelConfiguration = new ModelConfiguration();
var model = new EdmModel().Initialize();
var entityType = new EdmEntityType();
var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);
new NavigationPropertyMapper(new TypeMapper(mappingContext))
.Map(new MockPropertyInfo(typeof(NavigationPropertyMapperTests[]), "Nav"), entityType,
() => new EntityTypeConfiguration(typeof(object)));
Assert.Equal(0, model.Namespaces.Single().AssociationTypes.Count);
}
示例15: Apply_is_noop_when_unknown_dependent
public void Apply_is_noop_when_unknown_dependent()
{
var model = new EdmModel().Initialize();
var associationType = new EdmAssociationType().Initialize();
var navigationProperty = new EdmNavigationProperty { Association = associationType };
var foreignKeyAnnotation = new ForeignKeyAttribute("AId");
navigationProperty.Annotations.SetClrAttributes(new[] { foreignKeyAnnotation });
((IEdmConvention<EdmNavigationProperty>)new ForeignKeyNavigationPropertyAttributeConvention())
.Apply(navigationProperty, model);
Assert.Null(associationType.Constraint);
}