Condividi tramite


Facet (EDM)

Nel modello EDM (Entity Data Model) i facet rappresentano vincoli sui tipi di dati dichiarati come proprietà di entità. In CSDL (Conceptual Schema Definition Language) i facet non vengono utilizzati da Entity Framework. In SSDL (Store Schema Definition Language) i facet forniscono informazioni sui tipi di dati utilizzati dall'origine dati e su qualsiasi vincolo che potrebbe essere applicato dal sistema di gestione di database.

Nella dichiarazione SSDL di ProductEntityType riportata di seguito gli attributi di proprietà, quali MaxLength, Nullable, Precision, Scale e StoreGeneratedPattern, rappresentano facet. Una proprietà con il facet StoreGeneratedPattern="Identity" è la chiave primaria di una tabella di database. Una proprietà decorata con l'attributo StoreGeneratedPattern viene assegnata automaticamente dal sistema di gestione di database. La proprietà di un'entità mappata a questa colonna della tabella non viene impostata dal codice dell'applicazione e qualsiasi codice utilizzato per impostare la proprietà genera un'eccezione nell'origine dati.

<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>

I facet in CSDL non influiscono sul modello a oggetti progettato. La finestra di progettazione delle entità rimuove i facet in caso di modifica ai tipi di dati delle proprietà che decorano. Se specificato in CSDL, un attributo parallelo per l'oggetto StoreGeneratedPattern in SSDL, come quello illustrato sopra, non genererà un errore del compilatore.

Vedere anche

Riferimento

Facet