/// <inheritdoc /> public override EntitySetConfiguration AddEntitySet(string name, EntityTypeConfiguration entityType) { EntitySetConfiguration entitySetConfiguration = base.AddEntitySet(name, entityType); if (_isModelBeingBuilt) { ApplyEntitySetConventions(entitySetConfiguration); } return(entitySetConfiguration); }
public ActionConfiguration ReturnsFromEntitySet <TEntityType>(EntitySetConfiguration <TEntityType> entitySetConfiguration) where TEntityType : class { if (entitySetConfiguration == null) { throw Error.ArgumentNull("entitySetConfiguration"); } EntitySet = entitySetConfiguration.EntitySet; ReturnType = ModelBuilder.GetTypeConfigurationOrNull(typeof(TEntityType)); return(this); }
public void CtorThatTakesClrType_Sets_Property_Name() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); // Act EntitySetConfiguration entityset = new EntitySetConfiguration(builder, typeof(EntitySetConfigurationTest), "entityset"); // Assert Assert.Equal("entityset", entityset.Name); }
public void CtorThatTakesEntityTypeConfiguration_Sets_Property_EntityType() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration entityType = new EntityTypeConfiguration(new ODataModelBuilder(), typeof(EntitySetConfigurationTest)); // Act EntitySetConfiguration entityset = new EntitySetConfiguration(builder, entityType, "entityset"); // Assert Assert.Equal(entityType, entityset.EntityType); }
/// <summary> /// Constructs an instance of an <see cref="EntitySetLinkBuilderAnnotation" /> from an <see cref="EntitySetConfiguration" />. /// </summary> public EntitySetLinkBuilderAnnotation(EntitySetConfiguration entitySet) { if (entitySet == null) { throw Error.ArgumentNull("entitySet"); } _entitySetName = entitySet.Name; _feedSelfLinkBuilder = entitySet.GetFeedSelfLink(); _idLinkBuilder = entitySet.GetIdLink(); _editLinkBuilder = entitySet.GetEditLink(); _readLinkBuilder = entitySet.GetReadLink(); }
private void ApplyEntitySetConventions(EntitySetConfiguration entitySetConfiguration) { if (!_configuredEntitySets.Contains(entitySetConfiguration)) { _configuredEntitySets.Add(entitySetConfiguration); foreach (IEntitySetConvention convention in _conventions.OfType <IEntitySetConvention>()) { if (convention != null) { convention.Apply(entitySetConfiguration, this); } } } }
public EntitySetLinkBuilderAnnotation(EntitySetConfiguration entitySet) { if (entitySet == null) { throw Error.ArgumentNull("entitySet"); } _entitySet = entitySet; _feedSelfLinkBuilder = entitySet.GetFeedSelfLink(); _idLinkBuilder = entitySet.GetIdLink(); _editLinkBuilder = entitySet.GetEditLink(); _readLinkBuilder = entitySet.GetReadLink(); _navigationPropertyLinkBuilderLookup = new Dictionary <IEdmNavigationProperty, NavigationLinkBuilder>(); }
public EntitySetLinkBuilderAnnotation(EntitySetConfiguration entitySet) { if (entitySet == null) { throw Error.ArgumentNull("entitySet"); } _entitySet = entitySet; _feedSelfLinkBuilder = entitySet.GetFeedSelfLink(); _idLinkBuilder = entitySet.GetIdLink(); _editLinkBuilder = entitySet.GetEditLink(); _readLinkBuilder = entitySet.GetReadLink(); _navigationPropertyLinkBuilderLookup = new Dictionary<IEdmNavigationProperty, NavigationLinkBuilder>(); }
public ActionConfiguration ReturnsCollectionFromEntitySet <TElementEntityType>( EntitySetConfiguration <TElementEntityType> entitySetConfiguration) where TElementEntityType : class { if (entitySetConfiguration == null) { throw Error.ArgumentNull("entitySetConfiguration"); } Type clrCollectionType = typeof(IEnumerable <TElementEntityType>); EntitySet = entitySetConfiguration.EntitySet; IEdmTypeConfiguration elementType = ModelBuilder.GetTypeConfigurationOrNull(typeof(TElementEntityType)); ReturnType = new CollectionTypeConfiguration(elementType, clrCollectionType); return(this); }
public NavigationPropertyBindingConfiguration HasOptionalBinding <TTargetType>( Expression <Func <TEntityType, TTargetType> > navigationExpression, EntitySetConfiguration <TTargetType> targetSet) where TTargetType : class { if (navigationExpression == null) { throw Error.ArgumentNull("navigationExpression"); } if (targetSet == null) { throw Error.ArgumentNull("targetSet"); } return(_configuration.AddBinding(EntityType.HasOptional(navigationExpression), targetSet._configuration)); }
internal EntitySetConfiguration(ODataModelBuilder modelBuilder, EntitySetConfiguration configuration) { if (modelBuilder == null) { throw Error.ArgumentNull("modelBuilder"); } if (configuration == null) { throw Error.ArgumentNull("configuration"); } _configuration = configuration; _modelBuilder = modelBuilder; _entityType = new EntityTypeConfiguration <TEntityType>(modelBuilder, _configuration.EntityType); }
public NavigationPropertyBindingConfiguration HasOptionalBinding <TTargetType, TDerivedEntityType>( Expression <Func <TDerivedEntityType, TTargetType> > navigationExpression, EntitySetConfiguration <TTargetType> targetSet) where TTargetType : class where TDerivedEntityType : class, TEntityType { if (navigationExpression == null) { throw Error.ArgumentNull("navigationExpression"); } if (targetSet == null) { throw Error.ArgumentNull("targetSet"); } EntityTypeConfiguration <TDerivedEntityType> derivedEntityType = _modelBuilder.Entity <TDerivedEntityType>().DerivesFrom <TEntityType>(); return(_configuration.AddBinding(derivedEntityType.HasOptional(navigationExpression), targetSet._configuration)); }
private static void AddNavigationBindings(EntitySetConfiguration configuration, EdmEntitySet entitySet, EntitySetLinkBuilderAnnotation linkBuilder, ODataModelBuilder builder, Dictionary <Type, IEdmStructuredType> edmTypeMap, Dictionary <string, EdmEntitySet> edmEntitySetMap) { foreach (EntityTypeConfiguration entity in builder.ThisAndBaseAndDerivedTypes(configuration.EntityType)) { foreach (NavigationPropertyConfiguration navigation in entity.NavigationProperties) { NavigationPropertyBindingConfiguration binding = configuration.FindBinding(navigation); if (binding != null) { EdmEntityType edmEntityType = edmTypeMap[entity.ClrType] as EdmEntityType; IEdmNavigationProperty edmNavigationProperty = edmEntityType.NavigationProperties().Single(np => np.Name == navigation.Name); entitySet.AddNavigationTarget(edmNavigationProperty, edmEntitySetMap[binding.EntitySet.Name]); NavigationLinkBuilder linkBuilderFunc = configuration.GetNavigationPropertyLink(navigation); if (linkBuilderFunc != null) { linkBuilder.AddNavigationPropertyLinkBuilder(edmNavigationProperty, linkBuilderFunc); } } } } }
/// <summary> /// Binds the given navigation property to the target entity set. /// </summary> /// <param name="navigationConfiguration">The navigation property.</param> /// <param name="targetEntitySet">The target entity set.</param> /// <returns>The <see cref="NavigationPropertyBindingConfiguration"/> so that it can be further configured.</returns> public virtual NavigationPropertyBindingConfiguration AddBinding(NavigationPropertyConfiguration navigationConfiguration, EntitySetConfiguration targetEntitySet) { if (navigationConfiguration == null) { throw Error.ArgumentNull("navigationConfiguration"); } if (targetEntitySet == null) { throw Error.ArgumentNull("targetEntitySet"); } EntityTypeConfiguration declaringEntityType = navigationConfiguration.DeclaringEntityType; if (!(declaringEntityType.IsAssignableFrom(EntityType) || EntityType.IsAssignableFrom(declaringEntityType))) { throw Error.Argument("navigationConfiguration", SRResources.NavigationPropertyNotInHierarchy, declaringEntityType.FullName, EntityType.FullName, Name); } NavigationPropertyBindingConfiguration navigationPropertyBinding = null; if (_entitySetBindings.ContainsKey(navigationConfiguration)) { navigationPropertyBinding = _entitySetBindings[navigationConfiguration]; if (navigationPropertyBinding.EntitySet != targetEntitySet) { throw Error.NotSupported(SRResources.RebindingNotSupported); } } else { navigationPropertyBinding = new NavigationPropertyBindingConfiguration(navigationConfiguration, targetEntitySet); _entitySetBindings[navigationConfiguration] = navigationPropertyBinding; } return navigationPropertyBinding; }
public NavigationPropertyBinding(NavigationPropertyConfiguration navigationProperty, EntitySetConfiguration entitySet) { NavigationProperty = navigationProperty; EntitySet = entitySet; _linkFactory = null; }
public EntitySetConfigurationTest() { _builder = new ODataModelBuilder(); _entityset = new EntitySetConfiguration(_builder, typeof(EntitySetConfigurationTest), "entityset"); }
public EntitySetLinkBuilderAnnotationTest() { _modelBuilder = new ODataModelBuilder(); _entitySet = _modelBuilder.AddEntitySet("Customers", _modelBuilder.AddEntity(typeof(Customer))); }
public void CtorThatTakesClrType_Sets_Property_EntityType() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); // Act EntitySetConfiguration entityset = new EntitySetConfiguration(builder, typeof(EntitySetConfigurationTest), "entityset"); // Assert Assert.NotNull(entityset.EntityType); Assert.Equal(typeof(EntitySetConfigurationTest), entityset.EntityType.ClrType); }
private static EdmEntitySet AddEntitySet(this EdmEntityContainer container, EntitySetConfiguration entitySet, IDictionary <Type, IEdmStructuredType> edmTypeMap) { return(container.AddEntitySet(entitySet.Name, (IEdmEntityType)edmTypeMap[entitySet.EntityType.ClrType])); }
private static void AddNavigationBindings(EntitySetConfiguration configuration, EdmEntitySet entitySet, EntitySetLinkBuilderAnnotation linkBuilder, ODataModelBuilder builder, Dictionary<Type, IEdmStructuredType> edmTypeMap, Dictionary<string, EdmEntitySet> edmEntitySetMap) { foreach (EntityTypeConfiguration entity in builder.ThisAndBaseAndDerivedTypes(configuration.EntityType)) { foreach (NavigationPropertyConfiguration navigation in entity.NavigationProperties) { NavigationPropertyBinding binding = configuration.FindBinding(navigation); if (binding != null) { EdmEntityType edmEntityType = edmTypeMap[entity.ClrType] as EdmEntityType; IEdmNavigationProperty edmNavigationProperty = edmEntityType.NavigationProperties().Single(np => np.Name == navigation.Name); entitySet.AddNavigationTarget(edmNavigationProperty, edmEntitySetMap[binding.EntitySet.Name]); Func<EntityInstanceContext, IEdmNavigationProperty, Uri> linkBuilderFunc = configuration.GetNavigationPropertyLink(navigation); if (linkBuilderFunc != null) { linkBuilder.AddNavigationPropertyLinkBuilder(edmNavigationProperty, linkBuilderFunc); } } } } }
private static EdmEntitySet AddEntitySet(this EdmEntityContainer container, EntitySetConfiguration entitySet, IDictionary<Type, IEdmStructuredType> edmTypeMap) { return container.AddEntitySet(entitySet.Name, (IEdmEntityType)edmTypeMap[entitySet.EntityType.ClrType]); }
/// <summary> /// Binds the given navigation property to the target entity set. /// </summary> /// <param name="navigationConfiguration">The navigation property.</param> /// <param name="targetEntitySet">The target entity set.</param> /// <returns>The <see cref="NavigationPropertyBindingConfiguration"/> so that it can be further configured.</returns> public virtual NavigationPropertyBindingConfiguration AddBinding(NavigationPropertyConfiguration navigationConfiguration, EntitySetConfiguration targetEntitySet) { if (navigationConfiguration == null) { throw Error.ArgumentNull("navigationConfiguration"); } if (targetEntitySet == null) { throw Error.ArgumentNull("targetEntitySet"); } EntityTypeConfiguration declaringEntityType = navigationConfiguration.DeclaringEntityType; if (!(declaringEntityType.IsAssignableFrom(EntityType) || EntityType.IsAssignableFrom(declaringEntityType))) { throw Error.Argument("navigationConfiguration", SRResources.NavigationPropertyNotInHierarchy, declaringEntityType.FullName, EntityType.FullName, Name); } NavigationPropertyBindingConfiguration navigationPropertyBinding = null; if (_entitySetBindings.ContainsKey(navigationConfiguration)) { navigationPropertyBinding = _entitySetBindings[navigationConfiguration]; if (navigationPropertyBinding.EntitySet != targetEntitySet) { throw Error.NotSupported(SRResources.RebindingNotSupported); } } else { navigationPropertyBinding = new NavigationPropertyBindingConfiguration(navigationConfiguration, targetEntitySet); _entitySetBindings[navigationConfiguration] = navigationPropertyBinding; } return(navigationPropertyBinding); }