本文整理汇总了C#中System.Data.Entity.Core.Metadata.Edm.AssociationType类的典型用法代码示例。如果您正苦于以下问题:C# AssociationType类的具体用法?C# AssociationType怎么用?C# AssociationType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssociationType类属于System.Data.Entity.Core.Metadata.Edm命名空间,在下文中一共展示了AssociationType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Create_sets_properties_and_seals_the_instance
public static void Create_sets_properties_and_seals_the_instance()
{
var typeUsage = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
var associationType = new AssociationType("AssociationType", "Namespace", true, DataSpace.CSpace);
var source = new EntityType("Source", "Namespace", DataSpace.CSpace);
var target = new EntityType("Target", "Namespace", DataSpace.CSpace);
var sourceEnd = new AssociationEndMember("SourceEnd", source);
var targetEnd = new AssociationEndMember("TargetEnd", target);
var navigationProperty =
NavigationProperty.Create(
"NavigationProperty",
typeUsage,
associationType,
sourceEnd,
targetEnd,
new[]
{
new MetadataProperty(
"TestProperty",
TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
"value"),
});
Assert.Equal("NavigationProperty", navigationProperty.Name);
Assert.Same(typeUsage, navigationProperty.TypeUsage);
Assert.Same(associationType, navigationProperty.RelationshipType);
Assert.Same(sourceEnd, navigationProperty.FromEndMember);
Assert.Same(targetEnd, navigationProperty.ToEndMember);
Assert.True(navigationProperty.IsReadOnly);
var metadataProperty = navigationProperty.MetadataProperties.SingleOrDefault(p => p.Name == "TestProperty");
Assert.NotNull(metadataProperty);
Assert.Equal("value", metadataProperty.Value);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:35,代码来源:NavigationPropertyTests.cs
示例2: Apply_is_noop_when_existing_constraint
public void Apply_is_noop_when_existing_constraint()
{
var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
var property = EdmProperty.Primitive("Fk", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
var associationConstraint
= new ReferentialConstraint(
associationType.SourceEnd,
associationType.TargetEnd,
new[] { property },
new[] { property });
associationType.Constraint = associationConstraint;
var navigationProperty = new NavigationProperty("N", TypeUsage.Create(new EntityType("E", "N", DataSpace.CSpace)))
{
RelationshipType = associationType
};
((IEdmConvention<NavigationProperty>)new ForeignKeyNavigationPropertyAttributeConvention())
.Apply(navigationProperty, new EdmModel(DataSpace.CSpace));
Assert.Same(associationConstraint, navigationProperty.Association.Constraint);
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:27,代码来源:ForeignKeyAnnotationConventionTests.cs
示例3: HasCascadeDeletePath_should_return_true_for_transitive_cascade
public void HasCascadeDeletePath_should_return_true_for_transitive_cascade()
{
var model = new EdmModel(DataSpace.CSpace);
var entityTypeA = model.AddEntityType("A");
var entityTypeB = model.AddEntityType("B");
var entityTypeC = model.AddEntityType("B");
var associationTypeA
= new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
{
SourceEnd = new AssociationEndMember("S", entityTypeA),
TargetEnd = new AssociationEndMember("T", entityTypeB)
};
associationTypeA.SourceEnd.DeleteBehavior = OperationAction.Cascade;
model.AddAssociationType(associationTypeA);
var associationTypeB
= new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
{
SourceEnd = new AssociationEndMember("S", entityTypeB),
TargetEnd = new AssociationEndMember("T", entityTypeC)
};
associationTypeB.SourceEnd.DeleteBehavior = OperationAction.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));
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:32,代码来源:EdmModelExtensionsTests.cs
示例4: Apply_should_set_principal_end_kind_to_required_when_all_properties_not_nullable
public void Apply_should_set_principal_end_kind_to_required_when_all_properties_not_nullable()
{
var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
associationType.SourceEnd.RelationshipMultiplicity = RelationshipMultiplicity.ZeroOrOne;
var property1 = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
var property2 = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
var associationConstraint
= new ReferentialConstraint(
associationType.SourceEnd,
associationType.TargetEnd,
new[]
{
property1,
property2
},
new[]
{
property1,
property2
});
associationConstraint.ToProperties.Each(p => p.Nullable = false);
associationType.Constraint = associationConstraint;
(new ForeignKeyAssociationMultiplicityConvention())
.Apply(associationType, new DbModel(new EdmModel(DataSpace.CSpace), null));
Assert.True(associationType.SourceEnd.IsRequired());
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:35,代码来源:ForeignKeyAssociationMultiplicityConventionTests.cs
示例5: Apply_should_discover_for_self_reference
public void Apply_should_discover_for_self_reference()
{
var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
associationType.TargetEnd = new AssociationEndMember("T", associationType.SourceEnd.GetEntityType());
associationType.SourceEnd.RelationshipMultiplicity = RelationshipMultiplicity.ZeroOrOne;
associationType.TargetEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;
var pkProperty = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
associationType.SourceEnd.GetEntityType().AddKeyMember(pkProperty);
var fkProperty = EdmProperty.Primitive("NavId", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
associationType.TargetEnd.GetEntityType().AddMember(fkProperty);
associationType.TargetEnd.GetEntityType().AddNavigationProperty("Nav", associationType).ToEndMember = associationType.SourceEnd;
associationType.TargetEnd.GetEntityType().AddNavigationProperty("Foos", associationType);
// Foo.Id == Foo.NavId
((IEdmConvention<AssociationType>)new NavigationPropertyNameForeignKeyDiscoveryConvention())
.Apply(associationType, new EdmModel(DataSpace.CSpace));
Assert.NotNull(associationType.Constraint);
Assert.Same(associationType.TargetEnd, associationType.Constraint.ToRole);
Assert.Equal("NavId", associationType.Constraint.ToProperties.Single().Name);
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:27,代码来源:NavigationPropertyNameForeignKeyDiscoveryConventionTests.cs
示例6: GenerateForeignKeyAssociationType
private static void GenerateForeignKeyAssociationType(
AssociationType associationType, DbDatabaseMapping databaseMapping)
{
DebugCheck.NotNull(associationType);
DebugCheck.NotNull(databaseMapping);
Debug.Assert(associationType.Constraint != null);
var dependentEnd = associationType.Constraint.DependentEnd;
var principalEnd = associationType.GetOtherEnd(dependentEnd);
var principalEntityTypeMapping = GetEntityTypeMappingInHierarchy(databaseMapping, principalEnd.GetEntityType());
var dependentEntityTypeMapping = GetEntityTypeMappingInHierarchy(databaseMapping, dependentEnd.GetEntityType());
var foreignKeyConstraint
= new ForeignKeyBuilder(databaseMapping.Database, associationType.Name)
{
PrincipalTable =
principalEntityTypeMapping.MappingFragments.Single().Table,
DeleteAction = principalEnd.DeleteBehavior != OperationAction.None
? principalEnd.DeleteBehavior
: OperationAction.None
};
dependentEntityTypeMapping
.MappingFragments
.Single()
.Table
.AddForeignKey(foreignKeyConstraint);
foreignKeyConstraint.DependentColumns = associationType.Constraint.ToProperties.Select(
dependentProperty => dependentEntityTypeMapping.GetPropertyMapping(dependentProperty).ColumnProperty);
foreignKeyConstraint.SetAssociationType(associationType);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:33,代码来源:AssociationTypeMappingGenerator.cs
示例7: Apply_should_not_add_index_when_one_present
public void Apply_should_not_add_index_when_one_present()
{
var associationType
= new AssociationType("A", "N", false, DataSpace.SSpace)
{
Constraint
= new ReferentialConstraint(
new AssociationEndMember("F", new EntityType("P", "N", DataSpace.SSpace)),
new AssociationEndMember("T", new EntityType("D", "N", DataSpace.SSpace)),
new EdmProperty[] { },
new[] { new EdmProperty("A"), new EdmProperty("B") })
};
(new ForeignKeyIndexConvention()).Apply(associationType, null);
var consolidatedIndexes
= ConsolidatedIndex.BuildIndexes(
associationType.Name,
associationType.Constraint.ToProperties.Select(p => Tuple.Create(p.Name, p)));
Assert.Equal(1, consolidatedIndexes.Count());
(new ForeignKeyIndexConvention()).Apply(associationType, null);
consolidatedIndexes
= ConsolidatedIndex.BuildIndexes(
associationType.Name,
associationType.Constraint.ToProperties.Select(p => Tuple.Create(p.Name, p)));
Assert.Equal(1, consolidatedIndexes.Count());
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:31,代码来源:ForeignKeyIndexConventionTests.cs
示例8: Can_get_and_set_ends_via_wrapper_properties
public void Can_get_and_set_ends_via_wrapper_properties()
{
var associationType
= new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
{
SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)),
TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace))
};
var associationSet = new AssociationSet("A", associationType);
Assert.Null(associationSet.SourceSet);
Assert.Null(associationSet.TargetSet);
var sourceEntitySet = new EntitySet();
associationSet.SourceSet = sourceEntitySet;
var targetEntitySet = new EntitySet();
associationSet.TargetSet = targetEntitySet;
Assert.Same(sourceEntitySet, associationSet.SourceSet);
Assert.Same(targetEntitySet, associationSet.TargetSet);
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:25,代码来源:AssociationSetTests.cs
示例9: MatchDependentKeyProperty
/// <inheritdoc/>
protected override bool MatchDependentKeyProperty(
AssociationType associationType,
AssociationEndMember dependentAssociationEnd,
EdmProperty dependentProperty,
EntityType principalEntityType,
EdmProperty principalKeyProperty)
{
Check.NotNull(associationType, "associationType");
Check.NotNull(dependentAssociationEnd, "dependentAssociationEnd");
Check.NotNull(dependentProperty, "dependentProperty");
Check.NotNull(principalEntityType, "principalEntityType");
Check.NotNull(principalKeyProperty, "principalKeyProperty");
var otherEnd = associationType.GetOtherEnd(dependentAssociationEnd);
var navigationProperty
= dependentAssociationEnd.GetEntityType().NavigationProperties
.SingleOrDefault(n => n.ResultEnd == otherEnd);
if (navigationProperty == null)
{
return false;
}
return string.Equals(
dependentProperty.Name, navigationProperty.Name + principalKeyProperty.Name,
StringComparison.OrdinalIgnoreCase);
}
开发者ID:hallco978,项目名称:entityframework,代码行数:29,代码来源:NavigationPropertyNameForeignKeyDiscoveryConvention.cs
示例10: Can_get_and_set_constraint_via_wrapper_property
public void Can_get_and_set_constraint_via_wrapper_property()
{
var associationType
= new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
{
SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)),
TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace))
};
Assert.Null(associationType.Constraint);
Assert.False(associationType.IsForeignKey);
var property
= EdmProperty.CreatePrimitive("Fk", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
var referentialConstraint
= new ReferentialConstraint(
associationType.SourceEnd,
associationType.TargetEnd,
new[] { property },
new[] { property });
associationType.Constraint = referentialConstraint;
Assert.Same(referentialConstraint, associationType.Constraint);
Assert.True(associationType.IsForeignKey);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:27,代码来源:AssociationTypeTests.cs
示例11: 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 AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
var inverseAssociationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
inverseAssociationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
inverseAssociationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
var model = new EdmModel(DataSpace.CSpace);
model.AddAssociationType(inverseAssociationType);
var inverseNavigationProperty
= model.AddEntityType("T")
.AddNavigationProperty("N", inverseAssociationType);
inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);
navigationPropertyConfiguration.Configure(
new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
{
RelationshipType = associationType
}, model, new EntityTypeConfiguration(typeof(object)));
Assert.Same(associationType, inverseNavigationProperty.Association);
Assert.Same(associationType.SourceEnd, inverseNavigationProperty.ResultEnd);
Assert.Same(associationType.TargetEnd, inverseNavigationProperty.FromEndMember);
Assert.Equal(0, model.AssociationTypes.Count());
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:31,代码来源:NavigationPropertyConfigurationTests.cs
示例12: AddRelProperty
// <summary>
// Add the rel property induced by the specified relationship, (if the target
// end has a multiplicity of one)
// We only keep track of rel-properties that are "interesting"
// </summary>
// <param name="associationType"> the association relationship </param>
// <param name="fromEnd"> source end of the relationship traversal </param>
// <param name="toEnd"> target end of the traversal </param>
private void AddRelProperty(
AssociationType associationType,
AssociationEndMember fromEnd, AssociationEndMember toEnd)
{
if (toEnd.RelationshipMultiplicity
== RelationshipMultiplicity.Many)
{
return;
}
var prop = new RelProperty(associationType, fromEnd, toEnd);
if (_interestingRelProperties == null
||
!_interestingRelProperties.Contains(prop))
{
return;
}
var entityType = ((RefType)fromEnd.TypeUsage.EdmType).ElementType;
List<RelProperty> propList;
if (!_relPropertyMap.TryGetValue(entityType, out propList))
{
propList = new List<RelProperty>();
_relPropertyMap[entityType] = propList;
}
propList.Add(prop);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:34,代码来源:relpropertyhelper.cs
示例13: SetAssociationType
public static void SetAssociationType(
this ForeignKeyBuilder fk, AssociationType associationType)
{
DebugCheck.NotNull(fk);
DebugCheck.NotNull(associationType);
fk.GetMetadataProperties().SetAnnotation(AssociationType, associationType);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:8,代码来源:ForeignKeyBuilderExtensions.cs
示例14: SetAssociationType
public static void SetAssociationType(
this ForeignKeyBuilder fk, AssociationType associationType)
{
DebugCheck.NotNull(fk);
DebugCheck.NotNull(associationType);
fk.Annotations.SetAnnotation(AssociationType, associationType);
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:8,代码来源:ForeignKeyBuilderExtensions.cs
示例15: Can_get_and_set_configuration_facet
public void Can_get_and_set_configuration_facet()
{
var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
associationType.SetConfiguration(42);
Assert.Equal(42, associationType.GetConfiguration());
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:9,代码来源:AssociationTypeExtensionsTests.cs
示例16: Initialize_should_create_association_ends
public void Initialize_should_create_association_ends()
{
var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
Assert.NotNull(associationType.SourceEnd);
Assert.NotNull(associationType.TargetEnd);
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:9,代码来源:AssociationTypeExtensionsTests.cs
示例17: GetOtherEnd_should_return_correct_end
public void GetOtherEnd_should_return_correct_end()
{
var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
Assert.Same(associationType.SourceEnd, associationType.GetOtherEnd(associationType.TargetEnd));
Assert.Same(associationType.TargetEnd, associationType.GetOtherEnd(associationType.SourceEnd));
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:9,代码来源:AssociationTypeExtensionsTests.cs
示例18: Can_mark_association_as_independent
public void Can_mark_association_as_independent()
{
var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
Assert.False(associationType.IsIndependent());
associationType.MarkIndependent();
Assert.True(associationType.IsIndependent());
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:10,代码来源:AssociationTypeExtensionsTests.cs
示例19: IsManyToMany_should_be_true_when_source_many_and_target_many
public void IsManyToMany_should_be_true_when_source_many_and_target_many()
{
var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
associationType.SourceEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;
associationType.TargetEnd.RelationshipMultiplicity = RelationshipMultiplicity.Many;
Assert.True(associationType.IsManyToMany());
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:10,代码来源:AssociationTypeExtensionsTests.cs
示例20: Configure
internal override void Configure(
AssociationType associationType, AssociationEndMember dependentEnd,
EntityTypeConfiguration entityTypeConfiguration)
{
DebugCheck.NotNull(associationType);
DebugCheck.NotNull(dependentEnd);
DebugCheck.NotNull(entityTypeConfiguration);
associationType.MarkIndependent();
}
开发者ID:hallco978,项目名称:entityframework,代码行数:10,代码来源:IndependentConstraintConfiguration.cs
注:本文中的System.Data.Entity.Core.Metadata.Edm.AssociationType类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论