/// <summary> /// Binds the given navigation property to the target navigation source. /// </summary> /// <param name="navigationConfiguration">The navigation property.</param> /// <param name="targetNavigationSource">The target navigation source.</param> /// <returns>The <see cref="NavigationPropertyBindingConfiguration"/> so that it can be further configured.</returns> public virtual NavigationPropertyBindingConfiguration AddBinding(NavigationPropertyConfiguration navigationConfiguration, INavigationSourceConfiguration targetNavigationSource) { if (navigationConfiguration == null) { throw Error.ArgumentNull("navigationConfiguration"); } if (targetNavigationSource == null) { throw Error.ArgumentNull("targetNavigationSource"); } EntityTypeConfiguration declaringEntityType = navigationConfiguration.DeclaringEntityType; if (!(declaringEntityType.IsAssignableFrom(EntityType) || EntityType.IsAssignableFrom(declaringEntityType))) { throw Error.Argument("navigationConfiguration", SRResources.NavigationPropertyNotInHierarchy, declaringEntityType.FullName, EntityType.FullName, Name); } NavigationPropertyBindingConfiguration navigationPropertyBinding; if (_navigationPropertyBindings.TryGetValue(navigationConfiguration, out navigationPropertyBinding)) { if (navigationPropertyBinding.TargetNavigationSource != targetNavigationSource) { throw Error.NotSupported(SRResources.RebindingNotSupported); } } else { navigationPropertyBinding = new NavigationPropertyBindingConfiguration(navigationConfiguration, targetNavigationSource); _navigationPropertyBindings[navigationConfiguration] = navigationPropertyBinding; } return(navigationPropertyBinding); }
/// <summary> /// Configures the navigation link for the given navigation property for this navigation source. /// </summary> /// <param name="navigationProperty">The navigation property for which the navigation link is being generated.</param> /// <param name="navigationLinkBuilder">The builder used to generate the navigation link.</param> /// <returns>Returns itself so that multiple calls can be chained.</returns> public virtual INavigationSourceConfiguration HasNavigationPropertyLink(NavigationPropertyConfiguration navigationProperty, NavigationLinkBuilder navigationLinkBuilder) { if (navigationProperty == null) { throw Error.ArgumentNull("navigationProperty"); } if (navigationLinkBuilder == null) { throw Error.ArgumentNull("navigationLinkBuilder"); } EntityTypeConfiguration declaringEntityType = navigationProperty.DeclaringEntityType; if (!(declaringEntityType.IsAssignableFrom(EntityType) || EntityType.IsAssignableFrom(declaringEntityType))) { throw Error.Argument("navigationProperty", SRResources.NavigationPropertyNotInHierarchy, declaringEntityType.FullName, EntityType.FullName, Name); } _navigationPropertyLinkBuilders[navigationProperty] = navigationLinkBuilder; return(this); }