ReferenceOwnershipBuilder<TEntity,TRelatedEntity>.HasOne Method

Definition

Overloads

HasOne<TNewRelatedEntity>(Expression<Func<TRelatedEntity,TNewRelatedEntity>>)

Configures a relationship where this entity type has a reference that points to a single instance of the other type in the relationship.

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 WithMany(Expression<Func<TRelatedEntity,IEnumerable<TEntity>>>) or WithOne(Expression<Func<TRelatedEntity,TEntity>>) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

HasOne<TNewRelatedEntity>(String)

Configures a relationship where this entity type has a reference that points to a single instance of the other type in the relationship.

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 WithMany(String) or WithOne(String) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

HasOne<TNewRelatedEntity>(Expression<Func<TRelatedEntity,TNewRelatedEntity>>)

Configures a relationship where this entity type has a reference that points to a single instance of the other type in the relationship.

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 WithMany(Expression<Func<TRelatedEntity,IEnumerable<TEntity>>>) or WithOne(Expression<Func<TRelatedEntity,TEntity>>) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceNavigationBuilder<TRelatedEntity,TNewRelatedEntity> HasOne<TNewRelatedEntity> (System.Linq.Expressions.Expression<Func<TRelatedEntity,TNewRelatedEntity>> navigationExpression = default) where TNewRelatedEntity : class;
override this.HasOne : System.Linq.Expressions.Expression<Func<'RelatedEntity, 'NewRelatedEntity>> -> Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceNavigationBuilder<'RelatedEntity, 'NewRelatedEntity (requires 'RelatedEntity : null and 'NewRelatedEntity : null)> (requires 'NewRelatedEntity : null)
Public Overridable Function HasOne(Of TNewRelatedEntity As Class) (Optional navigationExpression As Expression(Of Func(Of TRelatedEntity, TNewRelatedEntity)) = Nothing) As ReferenceNavigationBuilder(Of TRelatedEntity, TNewRelatedEntity)

Type Parameters

TNewRelatedEntity

The entity type that this relationship targets.

Parameters

navigationExpression
Expression<Func<TRelatedEntity,TNewRelatedEntity>>

A lambda expression representing the reference navigation property on this entity type that represents the relationship (post => post.Blog). If no property is specified, the relationship will be configured without a navigation property on this end.

Returns

ReferenceNavigationBuilder<TRelatedEntity,TNewRelatedEntity>

An object that can be used to configure the relationship.

Applies to

HasOne<TNewRelatedEntity>(String)

Configures a relationship where this entity type has a reference that points to a single instance of the other type in the relationship.

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 WithMany(String) or WithOne(String) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceNavigationBuilder<TRelatedEntity,TNewRelatedEntity> HasOne<TNewRelatedEntity> (string navigationName) where TNewRelatedEntity : class;
override this.HasOne : string -> Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceNavigationBuilder<'RelatedEntity, 'NewRelatedEntity (requires 'RelatedEntity : null and 'NewRelatedEntity : null)> (requires 'NewRelatedEntity : null)
Public Overridable Function HasOne(Of TNewRelatedEntity As Class) (navigationName As String) As ReferenceNavigationBuilder(Of TRelatedEntity, TNewRelatedEntity)

Type Parameters

TNewRelatedEntity

The entity type that this relationship targets.

Parameters

navigationName
String

The name of the reference 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

ReferenceNavigationBuilder<TRelatedEntity,TNewRelatedEntity>

An object that can be used to configure the relationship.

Applies to