Facet (EDM)

在实体数据模型 (EDM) 中,facet 表示对声明为实体属性的数据类型的约束。在概念架构定义语言 (CSDL) 中,实体框架不使用 facet。在存储架构定义语言 (SSDL) 中,facet 提供有关数据源所使用的数据类型以及有关数据库管理系统可能应用的任何约束的信息。

在下面的 ProductEntityType 的 SSDL 声明中,MaxLengthNullablePrecisionScaleStoreGeneratedPattern 等属性特性都是 facet。具有 StoreGeneratedPattern="Identity" facet 的属性是数据库表的主键。用 StoreGeneratedPattern 属性 (Attribute) 修饰的属性 (Property) 由数据库管理系统自动分配。映射到此表列的实体属性不是应用程序代码设置的,并且用于设置该属性的任何代码都会在数据源中生成异常。

<EntityType Name="Product">
  <Key>
    <PropertyRef Name="ProductID" />
  </Key>
  <Property Name="ProductID" Type="int" Nullable="false"
                      StoreGeneratedPattern="Identity" />
  <Property Name="Name" Type="nvarchar" 
                      Nullable="false" MaxLength="50" />
  <Property Name="ProductNumber" 
                    Type="nvarchar" Nullable="false" MaxLength="25"/>
  <Property Name="MakeFlag" Type="bit" Nullable="false" />
  <Property Name="FinishedGoodsFlag" 
                    Type="bit" Nullable="false" />
  <Property Name="Color" Type="nvarchar" MaxLength="15" />
  <Property Name="SafetyStockLevel" Type="smallint" Nullable="false"/>
  <Property Name="ReorderPoint" Type="smallint" Nullable="false" />
  <Property Name="StandardCost" Type="money" Nullable="false" />
  <Property Name="ListPrice" Type="money" Nullable="false" />
  <Property Name="Size" Type="nvarchar" MaxLength="5" />
  <Property Name="SizeUnitMeasureCode" Type="nchar" MaxLength="3" />
  <Property Name="WeightUnitMeasureCode" Type="nchar" MaxLength="3"/>
  <Property Name="Weight" Type="decimal" Precision="8" Scale="2" />
  <Property Name="DaysToManufacture" Type="int" Nullable="false" />
  <Property Name="ProductLine" Type="nchar" MaxLength="2" />
  <Property Name="Class" Type="nchar" MaxLength="2" />
  <Property Name="Style" Type="nchar" MaxLength="2" />
  <Property Name="ProductSubcategoryID" Type="int" />
  <Property Name="ProductModelID" Type="int" />
  <Property Name="SellStartDate" Type="datetime" Nullable="false" />
  <Property Name="SellEndDate" Type="datetime" />
  <Property Name="DiscontinuedDate" Type="datetime" />
  <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
  <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
</EntityType>

CSDL 中的 facet 不会影响正在设计的对象模型。如果对 facet 所修饰的属性的数据类型进行了任何更改,实体设计器都会删除这些 facet。如果在 CSDL 中为 SSDL 中的 StoreGeneratedPattern(如上所示)指定了 CSDL 中的并行属性,则不会导致编译器错误。

另请参见

参考

Facet