EntityTypeConfiguration<TEntityType>.HasKey<TKey> Method (Expression<Func<TEntityType, TKey>>)

 

Configures the primary key property(s) for this entity type.

Namespace:   System.Data.Entity.ModelConfiguration
Assembly:  EntityFramework (in EntityFramework.dll)

[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public EntityTypeConfiguration<TEntityType> HasKey<TKey>(
	Expression<Func<TEntityType, TKey>> keyExpression
)

Parameters

keyExpression
Type: System.Linq.Expressions.Expression<Func<TEntityType, TKey>>

A lambda expression representing the property to be used as the primary key. C#: t =&gt; t.Id VB.Net: Function(t) t.Id If the primary key is made up of multiple properties then specify an anonymous type including the properties. C#: t =&gt; new { t.Id1, t.Id2 } VB.Net: Function(t) New With { t.Id1, t.Id2 }

Return Value

Type: System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<TEntityType>

The same EntityTypeConfiguration instance so that multiple calls can be chained.

Type Parameters

TKey

The type of the key.