EntityTypeConfiguration<TEntityType>.HasKey<TKey> 方法
[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]
為此實體類型設定主索引鍵屬性。
命名空間: System.Data.Entity.ModelConfiguration
組件: EntityFramework (在 EntityFramework.dll 中)
語法
'宣告
<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")> _
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Function HasKey(Of TKey) ( _
keyExpression As Expression(Of Func(Of TEntityType, TKey)) _
) As EntityTypeConfiguration(Of TEntityType)
'用途
Dim instance As EntityTypeConfiguration
Dim keyExpression As Expression(Of Func(Of TEntityType, TKey))
Dim returnValue As EntityTypeConfiguration(Of TEntityType)
returnValue = instance.HasKey(keyExpression)
[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public EntityTypeConfiguration<TEntityType> HasKey<TKey>(
Expression<Func<TEntityType, TKey>> keyExpression
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1011:ConsiderPassingBaseTypesAsParameters")]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TKey>
EntityTypeConfiguration<TEntityType>^ HasKey(
Expression<Func<TEntityType, TKey>^>^ keyExpression
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")>]
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
member HasKey :
keyExpression:Expression<Func<'TEntityType, 'TKey>> -> EntityTypeConfiguration<'TEntityType>
JScript does not support generic types and methods.
類型參數
- TKey
索引鍵的類型。
參數
- keyExpression
類型:System.Linq.Expressions.Expression<Func<TEntityType, TKey>>
Lambda 運算式,表示要當做主索引鍵使用的屬性。 C#:t => t.Id VB.Net:Function(t) t.Id。若主索引鍵由多個屬性組成,請指定匿名類型 (包括屬性)。 C#:t => new { t.Id1, t.Id2 } VB.Net:Function(t) New With { t.Id1, t.Id2 }
傳回值
類型:System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<TEntityType>
相同的 EntityTypeConfiguration 執行個體,以便鏈結多個呼叫。