Key 元素 (SSDL)

以存储架构定义语言 (SSDL) 表示的 Key 元素表示基础数据库中某个表的主键。 KeyEntityType 元素的一个子元素,表示表中的一行。 主键是通过引用在 EntityType 元素上定义的一个或多个 Property 元素在 Key 元素中定义的。

Key 元素可以具有以下子元素(按所列顺序):

没有适用于 Key 元素的特性。

示例

下面的示例演示具有引用一个属性的键的 EntityType 元素:

<EntityType Name="Customers">
  <Documentation>
    <Summary>Summary here.</Summary>
    <LongDescription>Long description here.</LongDescription>
  </Documentation>
  <Key>
    <PropertyRef Name="CustomerId" />
  </Key>
  <Property Name="CustomerId" Type="int" Nullable="false" />
  <Property Name="Name" Type="nvarchar(max)" Nullable="false" />
</EntityType>

另请参见

概念

实体框架概述
SSDL 规范

其他资源

CSDL、SSDL 和 MSL 规范
ADO.NET Entity Data Model Tools