EntityTypeBuilder<TEntity>.HasKey Method

Definition

Overloads

HasKey(Expression<Func<TEntity,Object>>)

Sets the properties that make up the primary key for this entity type.

HasKey(String[])

Sets the properties that make up the primary key for this entity type.

HasKey(Expression<Func<TEntity,Object>>)

Sets the properties that make up the primary key for this entity type.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder HasKey (System.Linq.Expressions.Expression<Func<TEntity,object>> keyExpression);
public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder HasKey (System.Linq.Expressions.Expression<Func<TEntity,object?>> keyExpression);
override this.HasKey : System.Linq.Expressions.Expression<Func<'Entity, obj>> -> Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder
Public Overridable Function HasKey (keyExpression As Expression(Of Func(Of TEntity, Object))) As KeyBuilder

Parameters

keyExpression
Expression<Func<TEntity,Object>>

A lambda expression representing the primary key property(s) (blog => blog.Url).

If the primary key is made up of multiple properties then specify an anonymous type including the properties (post => new { post.Title, post.BlogId }).

Returns

An object that can be used to configure the primary key.

Applies to

HasKey(String[])

Sets the properties that make up the primary key for this entity type.

public virtual Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder<TEntity> HasKey (params string[] propertyNames);
override this.HasKey : string[] -> Microsoft.EntityFrameworkCore.Metadata.Builders.KeyBuilder<'Entity (requires 'Entity : null)>
Public Overridable Function HasKey (ParamArray propertyNames As String()) As KeyBuilder(Of TEntity)

Parameters

propertyNames
String[]

The names of the properties that make up the primary key.

Returns

KeyBuilder<TEntity>

An object that can be used to configure the primary key.

Applies to