Elemento Function (SSDL)

La definizione dell'elemento Function in SSDL (Store Schema Definition Language) in EDM (Entity Data Model) specifica che nel database è presente una stored procedure. Gli elementi dei parametri nidificati specificano i nomi dei parametri e i relativi tipi di dati. Queste definizioni identificano una stored procedure che può essere mappata a un'entità e alle relative proprietà.

Nella versione corrente di Entity Framework l'attributo IsComposable di una dichiarazione di funzione che rappresenta una stored procedure deve essere impostato su false. Questa impostazione indica che i risultati restituiti dalla procedura non possono essere utilizzati nella clausola FROM di altre istruzioni SQL.

Per una procedura che prevede l'utilizzo di stored procedure, vedere Procedura: definire un modello con una stored procedure (Entity Framework).

Nell'esempio seguente vengono illustrati i metadati SSDL per la funzione SUBSTRING.

<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="Northwind" Alias="Self" 
xmlns:edm="https://schemas.microsoft.com/ado/2006/04/edm/ssdl"
   xmlns="https://schemas.microsoft.com/ado/2006/04/edm/ssdl">

   <! Other declarations.-->
  <Function Name="SUBSTRING" ReturnType="varchar" BuiltIn="true">
    <Documentation> 
       <Summary>Function accepts a source string, the starting position
         and the length of the sub-string to be extracted</Summary> 
       <LongDescription>Long Description if needed. </LongDescription> 
    </Documentation>

    <Parameter Name="str" Mode="In" Type="varchar" />
    <Parameter Name="start" Mode="In" Type="int">
      <Documentation> 
        <Summary>The starting position of the substring</Summary> 
        <LongDescription>Long Description.</LongDescription> 
      </Documentation>
    </Parameter>

    <Parameter Name="length" Mode="In" Type="int" />
  </Function>

</Schema>

Le dichiarazioni SSDL seguenti specificano tre stored procedure utilizzate per creare, aggiornare ed eliminare le entità e i dati contenuti: CreateVendor, UpdateVendor e DeleteVendor.

<Function Name="CreateVendor" IsComposable="false" Schema="dbo">    
    <Parameter Name="ID" Type="int" />    
    <Parameter Name="Name" Type="nvarchar" />    
    <Parameter Name="Description" Type="nvarchar(max)" />    
  </Function>

  <Function Name="UpdateVendor" IsComposable="false" Schema="dbo">
    <Parameter Name="ID" Type="int" />
    <Parameter Name="Name" Type="nvarchar" />
    <Parameter Name="Description" Type="nvarchar(max)" />
  </Function>

  <Function Name="DeleteVendor" IsComposable="false" Schema="dbo">
    <Parameter Name="ID" Type="int" />    
  </Function>
</Schema>

Vedere anche

Attività

Procedura: definire un modello con una stored procedure (Entity Framework)

Concetti

Supporto delle stored procedure (Entity Framework)