public void RemoveFromUncontainedNavigationProperty( IBindableModelContext context, IEntity targetEntity, INavigationProperty navigationProperty, IEnumerable <IEntity> entitiesToRemove) { ThrowIfContained(navigationProperty); if (navigationProperty.IsCollection()) { IUncontainedCollectionNavigationPropertyBinding binding; if (context.TryGetBinding(navigationProperty, out binding)) { entitiesToRemove.ForEach(entityToRemove => binding.Remove(targetEntity, entityToRemove)); return; } } else { IUncontainedNavigationPropertyBinding binding; if (context.TryGetBinding(navigationProperty, out binding)) { binding.Clear(targetEntity); return; } } throw new ArgumentException("The specified navigation property does not support the expected binding.", nameof(navigationProperty)); }
public static IEntity CreateEntityInContainedNavigationProperty( this INavigationProperty navigationProperty, IBindableModelContext context, IEntity parentEntity, IDictionary <string, IDependency> dependencies) { if (!navigationProperty.IsContained()) { throw new ArgumentException("Navigation property must be contained.", nameof(navigationProperty)); } if (navigationProperty.IsCollection()) { IContainedCollectionNavigationPropertyBinding binding; if (!context.TryGetBinding(navigationProperty, out binding)) { throw new ArgumentException("The specified navigation property does not support the expected binding.", nameof(navigationProperty)); } return(binding.CreateAndAdd(parentEntity, dependencies)); } else { IContainedNavigationPropertyBinding binding; if (!context.TryGetBinding(navigationProperty, out binding)) { throw new ArgumentException("The specified navigation property does not support the expected binding.", nameof(navigationProperty)); } return(binding.CreateAndSet(parentEntity, dependencies)); } }
public void SetUncontainedNavigationProperty( IBindableModelContext context, IEntity targetEntity, INavigationProperty navigationProperty, IEnumerable <IEntity> entities) { ThrowIfContained(navigationProperty); if (navigationProperty.IsCollection()) { IUncontainedCollectionNavigationPropertyBinding binding; if (context.TryGetBinding(navigationProperty, out binding)) { // TODO: think about having an AddRange method for better performance entities.ForEach(entity => binding.Add(targetEntity, entity)); return; } } else { IUncontainedNavigationPropertyBinding binding; if (context.TryGetBinding(navigationProperty, out binding)) { binding.Set(targetEntity, entities.Single()); return; } } throw new ArgumentException("The specified navigation property does not support the expected binding.", nameof(navigationProperty)); }
public static IEntity CreateEntityInEntitySet( this IEntitySet entitySet, IBindableModelContext context, IDictionary <string, IDependency> dependencies) { IEntitySetBinding binding; if (!context.TryGetBinding(entitySet, out binding)) { throw new ArgumentException("The specified entity set does not support the expected binding.", nameof(entitySet)); } return(binding.CreateAndAdd(dependencies)); }