Share via


ConventionTypeConfiguration<T>.HasKey<TProperty> Method

Definition

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

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public System.Data.Entity.ModelConfiguration.Configuration.ConventionTypeConfiguration<T> HasKey<TProperty> (System.Linq.Expressions.Expression<Func<T,TProperty>> keyExpression);
member this.HasKey : System.Linq.Expressions.Expression<Func<'T, 'Property>> -> System.Data.Entity.ModelConfiguration.Configuration.ConventionTypeConfiguration<'T (requires 'T : null)>
Public Function HasKey(Of TProperty) (keyExpression As Expression(Of Func(Of T, TProperty))) As ConventionTypeConfiguration(Of T)

Type Parameters

TProperty

The type of the key.

Parameters

keyExpression
Expression<Func<T,TProperty>>

A lambda expression representing the property to be used as the primary key. C#: t => 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 => new { t.Id1, t.Id2 } VB.Net: Function(t) New With { t.Id1, t.Id2 }

Returns

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

Attributes

Remarks

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

Applies to