本文整理汇总了C#中System.Data.Entity.Edm.EdmModel.AddAssociationType方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.AddAssociationType方法的具体用法?C# EdmModel.AddAssociationType怎么用?C# EdmModel.AddAssociationType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.Edm.EdmModel
的用法示例。
在下文中一共展示了EdmModel.AddAssociationType方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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));
}
示例3: HasCascadeDeletePath_should_return_true_for_transitive_cascade
public void HasCascadeDeletePath_should_return_true_for_transitive_cascade()
{
var model = new EdmModel().Initialize();
var entityTypeA = model.AddEntityType("A");
var entityTypeB = model.AddEntityType("B");
var entityTypeC = model.AddEntityType("B");
var associationTypeA = new EdmAssociationType().Initialize();
associationTypeA.SourceEnd.EntityType = entityTypeA;
associationTypeA.TargetEnd.EntityType = entityTypeB;
associationTypeA.SourceEnd.DeleteAction = EdmOperationAction.Cascade;
model.AddAssociationType(associationTypeA);
var associationTypeB = new EdmAssociationType().Initialize();
associationTypeB.SourceEnd.EntityType = entityTypeB;
associationTypeB.TargetEnd.EntityType = entityTypeC;
associationTypeB.SourceEnd.DeleteAction = EdmOperationAction.Cascade;
model.AddAssociationType(associationTypeB);
Assert.True(model.HasCascadeDeletePath(entityTypeA, entityTypeB));
Assert.True(model.HasCascadeDeletePath(entityTypeB, entityTypeC));
Assert.True(model.HasCascadeDeletePath(entityTypeA, entityTypeC));
Assert.False(model.HasCascadeDeletePath(entityTypeB, entityTypeA));
Assert.False(model.HasCascadeDeletePath(entityTypeC, entityTypeB));
Assert.False(model.HasCascadeDeletePath(entityTypeC, entityTypeA));
}
示例4: Apply_generates_constraint_when_simple_fk
public void Apply_generates_constraint_when_simple_fk()
{
var model = new EdmModel().Initialize();
var entityType = model.AddEntityType("E");
var associationType = model.AddAssociationType("A",
entityType, EdmAssociationEndKind.Optional,
entityType, EdmAssociationEndKind.Many);
var navigationProperty = entityType.AddNavigationProperty("N", associationType);
var fkProperty = entityType.AddPrimitiveProperty("Fk");
var foreignKeyAnnotation = new ForeignKeyAttribute("Fk");
navigationProperty.Annotations.SetClrAttributes(new[] { foreignKeyAnnotation });
((IEdmConvention<EdmNavigationProperty>)new ForeignKeyNavigationPropertyAttributeConvention())
.Apply(navigationProperty, model);
Assert.NotNull(associationType.Constraint);
Assert.True(associationType.Constraint.DependentProperties.Contains(fkProperty));
}
示例5: Apply_should_not_match_key_that_is_also_an_fk
public void Apply_should_not_match_key_that_is_also_an_fk()
{
var model = new EdmModel().Initialize();
var entityType = new EdmEntityType();
var property = new EdmProperty().AsPrimitive();
property.PropertyType.EdmType = EdmPrimitiveType.Int64;
entityType.DeclaredKeyProperties.Add(property);
var associationType
= model.AddAssociationType(
"A", new EdmEntityType(), EdmAssociationEndKind.Optional,
entityType, EdmAssociationEndKind.Many);
associationType.Constraint = new EdmAssociationConstraint();
associationType.Constraint.DependentProperties.Add(property);
((IEdmConvention<EdmEntityType>)new StoreGeneratedIdentityKeyConvention())
.Apply(entityType, model);
Assert.Null(entityType.DeclaredKeyProperties.Single().GetStoreGeneratedPattern());
}
示例6: Apply_throws_with_empty_foreign_key_properties
public void Apply_throws_with_empty_foreign_key_properties()
{
var model = new EdmModel().Initialize();
var entityType = model.AddEntityType("E");
var mockType = new MockType();
entityType.SetClrType(mockType);
var associationType = model.AddAssociationType("A",
entityType, EdmAssociationEndKind.Optional,
entityType, EdmAssociationEndKind.Many);
var navigationProperty = entityType.AddNavigationProperty("N", associationType);
var foreignKeyAnnotation = new ForeignKeyAttribute(",");
navigationProperty.Annotations.SetClrAttributes(new[] { foreignKeyAnnotation });
Assert.Equal(Strings.ForeignKeyAttributeConvention_EmptyKey("N", mockType.Object), Assert.Throws<InvalidOperationException>(() => ((IEdmConvention<EdmNavigationProperty>)new ForeignKeyNavigationPropertyAttributeConvention())
.Apply(navigationProperty, model)).Message);
}
示例7: Apply_should_match_key_that_is_an_fk_used_in_table_splitting
public void Apply_should_match_key_that_is_an_fk_used_in_table_splitting()
{
var model = new EdmModel().Initialize();
var entityType = new EdmEntityType();
var property = new EdmProperty().AsPrimitive();
property.PropertyType.EdmType = EdmPrimitiveType.Int64;
entityType.DeclaredKeyProperties.Add(property);
var targetConfig = new EntityTypeConfiguration(typeof(object));
targetConfig.ToTable("SharedTable");
entityType.SetConfiguration(targetConfig);
var sourceEntityType = new EdmEntityType();
var sourceConfig = new EntityTypeConfiguration(typeof(object));
sourceConfig.ToTable("SharedTable");
sourceEntityType.SetConfiguration(sourceConfig);
var associationType
= model.AddAssociationType(
"A", sourceEntityType, EdmAssociationEndKind.Required,
entityType, EdmAssociationEndKind.Required);
associationType.Constraint = new EdmAssociationConstraint();
associationType.Constraint.DependentProperties.Add(property);
((IEdmConvention<EdmEntityType>)new StoreGeneratedIdentityKeyConvention())
.Apply(entityType, model);
Assert.Equal(
DbStoreGeneratedPattern.Identity,
entityType.DeclaredKeyProperties.Single().GetStoreGeneratedPattern());
}
示例8: CreateModelFixture
private static EdmModel CreateModelFixture(
out EdmEntityType declaringEntityType, out EdmEntityType complexEntityType)
{
var model = new EdmModel().Initialize();
declaringEntityType = model.AddEntityType("E");
complexEntityType = model.AddEntityType("C");
complexEntityType.AddPrimitiveProperty("P");
var associationType
= model.AddAssociationType(
"A",
declaringEntityType, EdmAssociationEndKind.Many,
complexEntityType, EdmAssociationEndKind.Optional);
declaringEntityType.AddNavigationProperty("E.C", associationType);
return model;
}
示例9: AddAssociationSet_should_create_and_add_to_default_container
public void AddAssociationSet_should_create_and_add_to_default_container()
{
var model = new EdmModel().Initialize();
var sourceEntityType = model.AddEntityType("Source");
var targetEntityType = model.AddEntityType("Target");
var associationType = model.AddAssociationType(
"Foo",
sourceEntityType, EdmAssociationEndKind.Required,
targetEntityType, EdmAssociationEndKind.Many);
var associationSet = model.AddAssociationSet("FooSet", associationType);
Assert.NotNull(associationSet);
Assert.Equal("FooSet", associationSet.Name);
Assert.Same(associationType, associationSet.ElementType);
Assert.True(model.Containers.Single().AssociationSets.Contains(associationSet));
}
示例10: AddAssociationType_should_create_and_add_to_default_namespace
public void AddAssociationType_should_create_and_add_to_default_namespace()
{
var model = new EdmModel().Initialize();
var sourceEntityType = model.AddEntityType("Source");
var targetEntityType = model.AddEntityType("Target");
var associationType = model.AddAssociationType(
"Foo",
sourceEntityType, EdmAssociationEndKind.Required,
targetEntityType, EdmAssociationEndKind.Many);
Assert.NotNull(associationType);
Assert.Equal("Foo", associationType.Name);
Assert.Same(sourceEntityType, associationType.SourceEnd.EntityType);
Assert.Equal(EdmAssociationEndKind.Required, associationType.SourceEnd.EndKind);
Assert.Same(targetEntityType, associationType.TargetEnd.EntityType);
Assert.Equal(EdmAssociationEndKind.Many, associationType.TargetEnd.EndKind);
Assert.True(model.Namespaces.Single().AssociationTypes.Contains(associationType));
}
示例11: RemoveAssociationType_should_remove_type_and_set
public void RemoveAssociationType_should_remove_type_and_set()
{
var model = new EdmModel().Initialize();
var associationType = model.AddAssociationType(
"A",
new EdmEntityType(), EdmAssociationEndKind.Optional,
new EdmEntityType(), EdmAssociationEndKind.Many);
model.AddAssociationSet("FooSet", associationType);
model.RemoveAssociationType(associationType);
Assert.Equal(0, model.GetAssociationTypes().Count());
Assert.Equal(0, model.Containers.First().AssociationSets.Count());
}
示例12: GetAssociationsBetween_should_return_matching_associations
public void GetAssociationsBetween_should_return_matching_associations()
{
var model = new EdmModel().Initialize();
var entityTypeA = model.AddEntityType("Foo");
var entityTypeB = model.AddEntityType("Bar");
Assert.Equal(0, model.GetAssociationTypesBetween(entityTypeA, entityTypeB).Count());
model.AddAssociationType(
"Foo_Bar",
entityTypeA, EdmAssociationEndKind.Optional,
entityTypeB, EdmAssociationEndKind.Many);
model.AddAssociationType(
"Bar_Foo",
entityTypeB, EdmAssociationEndKind.Optional,
entityTypeA, EdmAssociationEndKind.Many);
Assert.Equal(2, model.GetAssociationTypesBetween(entityTypeA, entityTypeB).Count());
Assert.Equal(2, model.GetAssociationTypesBetween(entityTypeB, entityTypeA).Count());
Assert.Equal(0, model.GetAssociationTypesBetween(entityTypeA, entityTypeA).Count());
}
示例13: Generate_can_map_foreign_key_association_type
public void Generate_can_map_foreign_key_association_type()
{
var model = new EdmModel().Initialize();
var principalEntityType = model.AddEntityType("P");
principalEntityType.SetClrType(typeof(object));
var dependentEntityType = model.AddEntityType("D");
dependentEntityType.SetClrType(typeof(string));
var dependentProperty1 = dependentEntityType.AddPrimitiveProperty("FK1");
dependentProperty1.PropertyType.EdmType = EdmPrimitiveType.Int32;
var dependentProperty2 = dependentEntityType.AddPrimitiveProperty("FK2");
dependentProperty2.PropertyType.EdmType = EdmPrimitiveType.String;
model.AddEntitySet("PSet", principalEntityType);
model.AddEntitySet("DSet", dependentEntityType);
var associationType
= model.AddAssociationType("P_D",
principalEntityType, EdmAssociationEndKind.Required,
dependentEntityType, EdmAssociationEndKind.Many);
associationType.Constraint
= new EdmAssociationConstraint
{
DependentEnd = associationType.TargetEnd,
DependentProperties = new[] { dependentProperty1, dependentProperty2 },
};
associationType.SourceEnd.DeleteAction = EdmOperationAction.Cascade;
var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest).Generate(model);
var dependentTable = databaseMapping.GetEntityTypeMapping(dependentEntityType).TypeMappingFragments.Single().Table;
var foreignKeyConstraint = dependentTable.ForeignKeyConstraints.Single();
Assert.Equal(2, dependentTable.Columns.Count());
Assert.Equal(2, foreignKeyConstraint.DependentColumns.Count);
Assert.Equal(DbOperationAction.Cascade, foreignKeyConstraint.DeleteAction);
Assert.Equal(associationType.Name, foreignKeyConstraint.Name);
var foreignKeyColumn = foreignKeyConstraint.DependentColumns.First();
Assert.False(foreignKeyColumn.IsNullable);
Assert.Equal("FK1", foreignKeyColumn.Name);
}