共用方式為


Facet (EDM)

在 Entity Data Model (EDM) 中,Facet 代表針對宣告做為實體屬性之資料型別的條件約束。在概念結構定義語言 (CSDL) 中,Entity Framework 則不會使用 Facet。在存放結構定義語言 (SSDL) 中,Facet 所提供的資訊則有關資料來源使用的資料型別,以及資料庫管理系統可能會套用的任何條件約束。

在下列 ProductEntityType 的 SSDL 宣告中,屬性的屬性 (Property Attribute) 即為 Facet,例如 MaxLengthNullablePrecisionScaleStoreGeneratedPattern。具有 StoreGeneratedPattern="Identity" Facet 的屬性 (Property) 是資料庫資料表的主索引鍵。以 StoreGeneratedPattern 屬性 (Attribute) 裝飾的屬性 (Property),則是由資料庫管理系統自動指派的。對應到資料表中這個資料行的實體屬性 (Property) 並不是由應用程式程式碼設定的,而且任何用來設定該屬性 (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 所裝飾之屬性 (Property) 的資料型別有任何變更,實體設計工具就會移除該 Facet。在 CSDL 中有關 SSDL StoreGeneratedPattern (如上所示) 的平行屬性 (Attribute) 則不會造成編譯器錯誤 (如果 CSDL 中有指定的話)。

另請參閱

參考

Facet