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)); }
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); } }
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; }
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); }