本文整理汇总了C#中System.Data.Entity.Edm.EdmEntityType.AddNavigationProperty方法的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityType.AddNavigationProperty方法的具体用法?C# EdmEntityType.AddNavigationProperty怎么用?C# EdmEntityType.AddNavigationProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Entity.Edm.EdmEntityType
的用法示例。
在下文中一共展示了EdmEntityType.AddNavigationProperty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddNavigationProperty_should_create_and_add_navigation_property
public void AddNavigationProperty_should_create_and_add_navigation_property()
{
var entityType = new EdmEntityType();
var associationType = new EdmAssociationType();
var navigationProperty = entityType.AddNavigationProperty("N", associationType);
Assert.NotNull(navigationProperty);
Assert.Equal("N", navigationProperty.Name);
Assert.Same(associationType, navigationProperty.Association);
Assert.True(entityType.NavigationProperties.Contains(navigationProperty));
}
示例2: Map
public void Map(
PropertyInfo propertyInfo, EdmEntityType entityType, Func<EntityTypeConfiguration> entityTypeConfiguration)
{
Contract.Requires(propertyInfo != null);
Contract.Requires(entityType != null);
Contract.Requires(entityTypeConfiguration != null);
var targetType = propertyInfo.PropertyType;
var targetAssociationEndKind = EdmAssociationEndKind.Optional;
if (targetType.IsCollection(out targetType))
{
targetAssociationEndKind = EdmAssociationEndKind.Many;
}
var targetEntityType = _typeMapper.MapEntityType(targetType);
if (targetEntityType != null)
{
var sourceAssociationEndKind
= targetAssociationEndKind.IsMany()
? EdmAssociationEndKind.Optional
: EdmAssociationEndKind.Many;
var associationType = _typeMapper.MappingContext.Model.AddAssociationType(
entityType.Name + "_" + propertyInfo.Name,
entityType,
sourceAssociationEndKind,
targetEntityType,
targetAssociationEndKind);
_typeMapper.MappingContext.Model.AddAssociationSet(associationType.Name, associationType);
var navigationProperty
= entityType.AddNavigationProperty(propertyInfo.Name, associationType);
navigationProperty.SetClrPropertyInfo(propertyInfo);
_typeMapper.MappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(
propertyInfo,
() => entityTypeConfiguration().Navigation(propertyInfo));
new AttributeMapper(_typeMapper.MappingContext.AttributeProvider)
.Map(propertyInfo, navigationProperty.Annotations);
}
}
示例3: 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;
}
示例4: GetNavigationProperty_should_return_correct_property
public void GetNavigationProperty_should_return_correct_property()
{
var entityType = new EdmEntityType();
var associationType = new EdmAssociationType().Initialize();
var property = entityType.AddNavigationProperty("Foo", associationType);
var foundProperty = entityType.GetNavigationProperty("Foo");
Assert.NotNull(foundProperty);
Assert.Same(property, foundProperty);
}