Facets (EDM)

In the Entity Data Model (EDM), facets represent constraints on data types that are declared as properties of entities. In conceptual schema definition language (CSDL) facets are not used by the Entity Framework. In store schema definition language (SSDL), facets provide information about the data types used by the data source and about any constraints that might be applied by the database management system.

In the following SSDL declaration of the Product EntityType, the property attributes, such as MaxLength, Nullable, Precision, Scale, and StoreGeneratedPattern, are facets. A property with the StoreGeneratedPattern="Identity" facet is the primary key of a database table. A property decorated with the StoreGeneratedPattern attribute is assigned automatically by the database management system. The property of an entity mapped to this column of the table is not set by application code, and any code used to set the property generates an exception in the data source.

<EntityType Name="Product">
    <PropertyRef Name="ProductID" />
  <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" />

Facets in CSDL have no effect on the object model being designed. The entity designer removes facets if any changes are made to the data types of properties they decorate. A parallel attribute in CSDL for the StoreGeneratedPattern in SSDL as shown above, if specified in CSDL, will not cause a compiler error.

See Also