Share via


QueryTypeBuilder<TQuery>.HasOne<TRelatedEntity> Method

Definition

Configures a relationship where this query 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<TQuery,TRelatedEntity> HasOne<TRelatedEntity> (System.Linq.Expressions.Expression<Func<TQuery,TRelatedEntity>> navigationExpression = default) where TRelatedEntity : class;
override this.HasOne : System.Linq.Expressions.Expression<Func<'Query, 'RelatedEntity>> -> Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceNavigationBuilder<'Query, 'RelatedEntity (requires 'Query : null and 'RelatedEntity : null)> (requires 'RelatedEntity : null)
Public Overridable Function HasOne(Of TRelatedEntity As Class) (Optional navigationExpression As Expression(Of Func(Of TQuery, TRelatedEntity)) = Nothing) As ReferenceNavigationBuilder(Of TQuery, TRelatedEntity)

Type Parameters

TRelatedEntity

The query type that this relationship targets.

Parameters

navigationExpression
Expression<Func<TQuery,TRelatedEntity>>

A lambda expression representing the reference navigation property on this query 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<TQuery,TRelatedEntity>

An object that can be used to configure the relationship.

Applies to