EntityTypeBuilder<TEntity>.HasMany Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
HasMany<TRelatedEntity>(Expression<Func<TEntity,IEnumerable<TRelatedEntity>>>) |
Configures a relationship where this entity type has a collection that contains instances of the other type in the relationship. |
HasMany<TRelatedEntity>(String) |
Configures a relationship where this entity type has a collection that contains instances of the other type in the relationship. |
HasMany<TRelatedEntity>(Expression<Func<TEntity,IEnumerable<TRelatedEntity>>>)
Configures a relationship where this entity type has a collection that contains instances of the other type in the relationship.
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.CollectionNavigationBuilder<TEntity,TRelatedEntity> HasMany<TRelatedEntity> (System.Linq.Expressions.Expression<Func<TEntity,System.Collections.Generic.IEnumerable<TRelatedEntity>>> navigationExpression = default) where TRelatedEntity : class;
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.CollectionNavigationBuilder<TEntity,TRelatedEntity> HasMany<TRelatedEntity> (System.Linq.Expressions.Expression<Func<TEntity,System.Collections.Generic.IEnumerable<TRelatedEntity>?>>? navigationExpression = default) where TRelatedEntity : class;
override this.HasMany : System.Linq.Expressions.Expression<Func<'Entity, seq<'RelatedEntity>>> -> Microsoft.EntityFrameworkCore.Metadata.Builders.CollectionNavigationBuilder<'Entity, 'RelatedEntity (requires 'Entity : null and 'RelatedEntity : null)> (requires 'RelatedEntity : null)
Public Overridable Function HasMany(Of TRelatedEntity As Class) (Optional navigationExpression As Expression(Of Func(Of TEntity, IEnumerable(Of TRelatedEntity))) = Nothing) As CollectionNavigationBuilder(Of TEntity, TRelatedEntity)
Type Parameters
- TRelatedEntity
The entity type that this relationship targets.
Parameters
- navigationExpression
- Expression<Func<TEntity,IEnumerable<TRelatedEntity>>>
A lambda expression representing the collection navigation property on this entity type that represents
the relationship (blog => blog.Posts
). If no property is specified, the relationship will be
configured without a navigation property on this end.
Returns
An object that can be used to configure the relationship.
Remarks
Note that calling this method with no parameters will explicitly configure this side of the relationship to use no navigation property, even if such a property exists on the entity type. If the navigation property is to be used, then it must be specified.
After calling this method, you should chain a call to WithOne(Expression<Func<TRelatedEntity,TEntity>>) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.
Applies to
HasMany<TRelatedEntity>(String)
Configures a relationship where this entity type has a collection that contains instances of the other type in the relationship.
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.CollectionNavigationBuilder<TEntity,TRelatedEntity> HasMany<TRelatedEntity> (string navigationName) where TRelatedEntity : class;
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.CollectionNavigationBuilder<TEntity,TRelatedEntity> HasMany<TRelatedEntity> (string? navigationName) where TRelatedEntity : class;
override this.HasMany : string -> Microsoft.EntityFrameworkCore.Metadata.Builders.CollectionNavigationBuilder<'Entity, 'RelatedEntity (requires 'Entity : null and 'RelatedEntity : null)> (requires 'RelatedEntity : null)
Public Overridable Function HasMany(Of TRelatedEntity As Class) (navigationName As String) As CollectionNavigationBuilder(Of TEntity, TRelatedEntity)
Type Parameters
- TRelatedEntity
The entity type that this relationship targets.
Parameters
- navigationName
- String
The name of the collection navigation property on this entity type that represents the relationship. If no property is specified, the relationship will be configured without a navigation property on this end.
Returns
An object that can be used to configure the relationship.
Remarks
Note that calling this method with no parameters will explicitly configure this side of the relationship to use no navigation property, even if such a property exists on the entity type. If the navigation property is to be used, then it must be specified.
After calling this method, you should chain a call to WithOne(Expression<Func<TRelatedEntity,TEntity>>) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.
Applies to
Entity Framework