EntityTypeConfiguration<TEntityType>.HasKey Method

Definition

Overloads

HasKey<TKey>(Expression<Func<TEntityType,TKey>>)

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

HasKey<TKey>(Expression<Func<TEntityType,TKey>>, Action<PrimaryKeyIndexConfiguration>)

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

HasKey<TKey>(Expression<Func<TEntityType,TKey>>)

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

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<TEntityType> HasKey<TKey> (System.Linq.Expressions.Expression<Func<TEntityType,TKey>> keyExpression);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<TEntityType> HasKey<TKey> (System.Linq.Expressions.Expression<Func<TEntityType,TKey>> keyExpression);
member this.HasKey : System.Linq.Expressions.Expression<Func<'EntityType, 'Key>> -> System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<'EntityType (requires 'EntityType : null)>
Public Function HasKey(Of TKey) (keyExpression As Expression(Of Func(Of TEntityType, TKey))) As EntityTypeConfiguration(Of TEntityType)

Type Parameters

TKey

The type of the key.

Parameters

keyExpression
Expression<Func<TEntityType,TKey>>

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

EntityTypeConfiguration<TEntityType>

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

Attributes

HasKey<TKey>(Expression<Func<TEntityType,TKey>>, Action<PrimaryKeyIndexConfiguration>)

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

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<TEntityType> HasKey<TKey> (System.Linq.Expressions.Expression<Func<TEntityType,TKey>> keyExpression, Action<System.Data.Entity.ModelConfiguration.Configuration.PrimaryKeyIndexConfiguration> buildAction);
member this.HasKey : System.Linq.Expressions.Expression<Func<'EntityType, 'Key>> * Action<System.Data.Entity.ModelConfiguration.Configuration.PrimaryKeyIndexConfiguration> -> System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<'EntityType (requires 'EntityType : null)>
Public Function HasKey(Of TKey) (keyExpression As Expression(Of Func(Of TEntityType, TKey)), buildAction As Action(Of PrimaryKeyIndexConfiguration)) As EntityTypeConfiguration(Of TEntityType)

Type Parameters

TKey

The type of the key.

Parameters

keyExpression
Expression<Func<TEntityType,TKey>>

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 }

buildAction
Action<PrimaryKeyIndexConfiguration>

A builder to configure the key.

Returns

EntityTypeConfiguration<TEntityType>

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

Attributes

Applies to