Delen via


OwnedNavigationBuilder<TOwnerEntity,TDependentEntity>.HasOne Method

Definition

Overloads

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

Configures a relationship where this entity type has a reference that points to a single instance of the other type in the 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.

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

Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs

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

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

Type Parameters

TNewRelatedEntity

The entity type that this relationship targets.

Parameters

navigationExpression
Expression<Func<TDependentEntity,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<TDependentEntity,TNewRelatedEntity>

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 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.

Applies to

HasOne<TNewRelatedEntity>(String)

Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs
Source:
OwnedNavigationBuilder%60.cs

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

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceNavigationBuilder<TDependentEntity,TNewRelatedEntity> HasOne<TNewRelatedEntity> (string navigationName) where TNewRelatedEntity : class;
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceNavigationBuilder<TDependentEntity,TNewRelatedEntity> HasOne<TNewRelatedEntity> (string? navigationName) where TNewRelatedEntity : class;
override this.HasOne : string -> Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceNavigationBuilder<'DependentEntity, 'NewRelatedEntity (requires 'DependentEntity : null and 'NewRelatedEntity : null)> (requires 'NewRelatedEntity : null)
Public Overridable Function HasOne(Of TNewRelatedEntity As Class) (navigationName As String) As ReferenceNavigationBuilder(Of TDependentEntity, 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<TDependentEntity,TNewRelatedEntity>

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

Applies to