ConventionTypeConfiguration<T>.HasKey<TProperty> Method (Expression<Func<T, TProperty>>)

 

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

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

[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public ConventionTypeConfiguration<T> HasKey<TProperty>(
	Expression<Func<T, TProperty>> keyExpression
)

Parameters

keyExpression
Type: System.Linq.Expressions.Expression<Func<T, TProperty>>

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.Configuration.ConventionTypeConfiguration<T>

The same ConventionTypeConfiguration<T> instance so that multiple calls can be chained.

Type Parameters

TProperty

The type of the key.

Calling this will have no effect once it has been configured.