链接:http://www.codeproject.com/Articles/675933/Returning-Multiple-Result-Sets-from-an-Entity-Fram

案例:下载

Create Visual Studio Project with Entity Data Model

Details to create an entity database-first app project are described in the MSDN tutorial. Follow the steps for building the app except using the sample database described above, the StoreDBModel for the model name, and the StoreDBEntities for the database connection string name.

Add Stored Procedures into the Entity Data Model

<FunctionImport Name="GetAllCategorisAndProducts" ReturnType="Collection(StoreDBModel.Category_SprocResult)" />
<FunctionImport Name="GetProductsCM" ReturnType="Collection(StoreDBModel.Product_SprocResult)" />

Change the code in the first FunctionImport node as shown below. This is actually to merge the second return type into the first FunctionImport node. The Type attribute in the second ReturnType node can easily be copied from the second FunctionImport node. After the merging, just leave the second FunctionImportnode there as it will automatically be deleted when we do the clean-up from the Model Browser later.

<FunctionImport Name="GetAllCategorisAndProducts">
<ReturnType Type="Collection(StoreDBModel.Category_SprocResult)" />
<ReturnType Type="Collection(StoreDBModel.Product_SprocResult)" />
</FunctionImport>
<FunctionImport Name="GetProductCM"
ReturnType="Collection(StoreDBModel.Product_SprocResult)" />
<FunctionImportMapping FunctionImportName="GetAllCategorisAndProducts"
FunctionName="StoreDBModel.Store.GetAllCategorisAndProducts">
<ResultMapping>
<ComplexTypeMapping TypeName="StoreDBModel.Category_SprocResult">
<ScalarProperty Name="CategoryID" ColumnName="CategoryID" />
<ScalarProperty Name="CategoryName" ColumnName="CategoryName" />
<ScalarProperty Name="ProductCount" ColumnName="ProductCount" />
</ComplexTypeMapping>
</ResultMapping>
</FunctionImportMapping>
<FunctionImportMapping FunctionImportName="GetProductCM" FunctionName="StoreDBModel.Store.GetProductCM">
<ResultMapping>
<ComplexTypeMapping TypeName="StoreDBModel.Product_SprocResult">
<ScalarProperty Name="ProductID" ColumnName="ProductID" />
<ScalarProperty Name="ProductName" ColumnName="ProductName" />
<ScalarProperty Name="CategoryID" ColumnName="CategoryID" />
<ScalarProperty Name="StatusCode" ColumnName="StatusCode" />
<ScalarProperty Name="StatusDescription" ColumnName="StatusDescription" />
<ScalarProperty Name="UnitPrice" ColumnName="UnitPrice" />
<ScalarProperty Name="AuditTime" ColumnName="AuditTime" />
</ComplexTypeMapping>
</ResultMapping>
</FunctionImportMapping>

Add the ResultMapping node from the second FunctionImportMapping into the firstFunctionImportMapping. Leave the entire second FunctionImportMapping node there for now.

<FunctionImportMapping FunctionImportName="GetAllCategorisAndProducts"
FunctionName="StoreDBModel.Store.GetAllCategorisAndProducts">
<ResultMapping>
<ComplexTypeMapping TypeName="StoreDBModel.Category_SprocResult">
<ScalarProperty Name="CategoryID" ColumnName="CategoryID" />
<ScalarProperty Name="CategoryName" ColumnName="CategoryName" />
<ScalarProperty Name="ProductCount" ColumnName="ProductCount" />
</ComplexTypeMapping>
</ResultMapping>
<ResultMapping>
<ComplexTypeMapping TypeName="StoreDBModel.Product_SprocResult">
<ScalarProperty Name="ProductID" ColumnName="ProductID" />
<ScalarProperty Name="ProductName" ColumnName="ProductName" />
<ScalarProperty Name="CategoryID" ColumnName="CategoryID" />
<ScalarProperty Name="StatusCode" ColumnName="StatusCode" />
<ScalarProperty Name="StatusDescription" ColumnName="StatusDescription" />
<ScalarProperty Name="UnitPrice" ColumnName="UnitPrice" />
<ScalarProperty Name="AuditTime" ColumnName="AuditTime" />
</ComplexTypeMapping>
</ResultMapping>
</FunctionImportMapping>
<FunctionImportMapping...>
. . .
</FunctionImportMapping>

  1. Open the EF designer by clicking the StoreDBModel.edmx file on the Solution Explorer. Then right-click any blank area on the designer and select the Update Model from Database…. This will open the Update Wizard window.
  2. Select the two stored procedures from the Stored Procedures and Functions list in the Add tab. Make sure that the Import selected stored procedures and functions into the entity model is checked and then click the Finish button. This will automatically add the function import mappings and the complex types for the stored procedures.
  3. Right-click any blank area on the EF designer and select the Model Browser. In the Model Browser, change the Complex Type name GetAllCategorisAndProducts_Result to Category_SprocResult, and the GetProductCM_Result to Product_SprocResult as shown below.
  4. Save the StoreDBModel.edmx file. The two complex type objects are created with the names we changed. Now we need to manually edit the XML content of the StoreDBModel.edmx file. Right-clicking the file, select the Open With…, and then XML (Text) Editor. Find the FunctionImport nodes under theedmx:ConceptualModels node:
  5. Find the FunctionImportMapping nodes under theedmx:Mappings/../En<FunctionImportMapping node.
  6. Clean up dummy stored procedure settings by opening the Model Browser again. Delete theGetProductCM in both Stored Procedures/Functions and Function Import lists. This will automatically delete all settings for the GetProductCM stored procedure mappings and also the method to call the dummy stored procedure in the StoreDBModel.Context.cs file.
  7. Save the StoreDBModel.edmx file. All changes in settings and clean-up will then be in effect.

What Happen When Updating Model

Will the manual editing for returning multiple result sets from the stored procedure be overwritten when updating the model due to any database schema changes? Based on results of my tests using the Visual Studio 2013, all the editing changes were kept intact when adding entities or other stored procedures into, or deleting any items from, the model except for deleting or refreshing the edited stored procedure mappings.

When adding or changing the input/output parameters in the stored procedure, the updates will automatically be refreshed in the model if executing the Refresh tab from the Update Model from Database (Update Wizard) screen. For example, adding @Test nvarchar(50) as an input parameter to the stored procedure,GetAllCategorisAndProducts, in the database then refreshing the model will insert the Parameter node into the stored procedure’s FunctionImport node even though it was manually edited before.

<FunctionImport Name="GetAllCategorisAndProducts">
<ReturnType Type="Collection(StoreDBModel.Category_SprocResult)" />
<ReturnType Type="Collection(StoreDBModel.Product_SprocResult)" />
<Parameter Name="Test" Mode="In" Type="String" />
</FunctionImport>

Automatic refreshing stored procedure complex type mappings due to changes in returning fields is not supported in any version of the EF, even for a stored procedure returning a single result set. We need to either re-add the stored procedure to the model after dropping the stored procedure and function import mappings from the model, or manually update the complex type using the Model Browser or the XML editor.

EF6调用存储过程,返回多个结果集处理的更多相关文章

  1. myabatis oracle 调用存储过程返回list结果集

    Mapper.xml 配置 <resultMap type="emp" id="empMap"> <id property="emp ...

  2. PostgreSQL 调用存储过程返回结果集

    创建返回结果集类型的存储过程: CREATE OR REPLACE FUNCTION public.f_get_member_info( id integer, productname charact ...

  3. jdbc调用存储过程获取多个结果集

    jdbc调用存储过程获取多个结果集 2017年07月26日 21:20:22 Kenny-Liu 阅读数:1486 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...

  4. Java 调用存储过程 返回结果集

    这里使用Oracle数据库的thin连接. 下面是存储过程SQL 1 createorreplaceprocedure proc3(stid in student.stuid%type, stname ...

  5. mybatis 调用存储过程 返回游标 实例

    存储过程示例: create or replace procedure Fsp_Plan_CheckPrj(v_grantno varchar2, v_deptcode number, v_curso ...

  6. sqlserver,获取调用存储过程返回数据的方法。

    1,获取存储过程最后select返回的结果集.SELECT 数据集返回值. 因为select返回的结果是一个表.所以返回的结果需要用一个表接收.使用临时表接收. 被调用的存储过程最后是这样:返回了一个 ...

  7. 整理sqlserver 级联更新和删除 c#调用存储过程返回值

    整理一下级联更新和删除 c#调用返回值 use master go IF exists(select 1 from sysdatabases where name='temp') BEGIN DROP ...

  8. java调用oracle存储过程返回多条结果集

    oracle版本:11g oracle存储过程,使用游标的方式返回多行.多列数据集合: CREATE OR REPLACE PROCEDURE SP_DATA_TEST( /*P_ID IN INT, ...

  9. [转].net 调用oracle存储过程返回多个记录集

    本文转自:http://www.netwinform.com/articleinfo.aspx?id=17 存储过程: CREATE OR REPLACE PROCEDURE p_query_cs ( ...

随机推荐

  1. SharePoint 2013版本功能对比介绍

    转:http://www.fengfly.com/plus/view-213720-1.html 在SharePoint使用中,经常纠结于版本问题,SharePoint 2013主要有免费的Found ...

  2. ESB、SOA、EAI异同【转】

    先说概念:       ESB:企业服务总线(ESB : Enterprise Service Bus):ESB 是一种开放的.基于标准的分布式同步或异步信息传递中间件.通过 XML.Web Serv ...

  3. linux内核申请内存函数

    kmap函数:    把某块高端内存映射到页表,然后返回给用户一个填好vitual字段的page结构    建立永久地址映射,不是简单的返回virtual字段的pageioremap:    驱动程序 ...

  4. shell脚本应用(4)--常用命令

    正则表达式 符号 用法 句号. 匹配任何单个字符  [shell用的是?] 符号^ 跟行首匹配 符号$ 跟行尾匹配 星号* 匹配0或若干个紧靠在星号前的字符[shell是0或若干跟字符] []结构 匹 ...

  5. Excel中VBA 连接 数据库 方法- 摘自网络

    Sub GetData() Dim strConn As String, strSQL As String Dim conn As ADODB.Connection Dim ds As ADODB.R ...

  6. 大型网站应用中MySQL的架构演变史

    没有什么东西是一成不变的,包含我们的理想和生活!MySQL作为一个免费的开源的关系型数据库,深受大家喜爱,从最初的无人问津到当下的去IOE,都体现出了MySQL举足轻重的作用.今天我们就从淘宝的发展来 ...

  7. 问题-[Delphi]用LoadLibrary加载DLL时返回0的错误

    问题现象:用LoadLibrary加载DLL一直返回0句柄,无法进行下一步操作,但同样的代码可以访问到别的DLL.问题处理:1.你加载的路径是不对的,一定要看好路径.2.你是在虚拟机中操作的DLL,因 ...

  8. Xsocket学习

    1.xsocket是一个轻量级的基于NIO的服务器框架,用于开发高性能.可扩展.多线程的服务器.该框架封装了线程处理,异步读写等方面的操作. 定义一个借口,继承IDataHandler,IConnec ...

  9. snowflake算法(java版)

     转自:http://www.cnblogs.com/haoxinyue/p/5208136.html 1. 数据库自增长序列或字段 最常见的方式.利用数据库,全数据库唯一. 优点: 1)简单,代码方 ...

  10. Fatal error: Call to undefined function mysql_connect()

    我在进行PHP环境搭建:Windows 7下安装配置PHP+Mysql+apache环境时,之前都没有什么问题,只是在验证PHP是否能连接Mysql时出现如下错误:Fatal error: Call ...