Function 元素 (SSDL)

实体数据模型 (EDM) 中存储架构定义语言 (SSDL) 中的 Function 元素定义指定数据库中存在存储过程。嵌套参数元素指定参数的名称和参数的数据类型。这些定义标识一个可以映射到实体及其属性的存储过程。

在实体框架的当前版本中,必须将表示存储过程的函数声明的 IsComposable 属性设置为 false。此设置指示过程返回的结果不能用于其他 SQL 语句的 FROM 子句。

有关存储过程的操作指南主题,请参见如何:使用存储过程定义模型(实体框架)

下面的示例演示 SUBSTRING 函数的 SSDL 元数据。

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

下列 SSDL 声明指定三个用于创建、更新和删除实体以及它们包含的数据的存储过程:CreateVendorUpdateVendorDeleteVendor

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

另请参见

任务

如何:使用存储过程定义模型(实体框架)

概念

存储过程支持(实体框架)