故事前提。。。。。。。。。。

一、返回顺序结果集

存储过程实例

CREATE PROCEDURE MultipleResultTypesSequentially
AS
select * from products
select * from customers

修改vs生成的存储过程代码

[Function(Name="dbo.MultipleResultTypesSequentially")]
[ResultType(typeof(MultipleResultTypesSequentiallyResult1))]
[ResultType(typeof(MultipleResultTypesSequentiallyResult2))]
public IMultipleResults MultipleResultTypesSequentially()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((IMultipleResults)(result.ReturnValue));
}

调用存储过程

IMultipleResults sprocResults =
db.MultipleResultTypesSequentially(); // First read products.
foreach (Product prod in sprocResults.GetResult<Product>())
{
Console.WriteLine(prod.ProductID);
} // Next read customers.
foreach (Customer cust in sprocResults.GetResult<Customer>())
{
Console.WriteLine(cust.CustomerID);
}

二、多个结果返回集(如不同参数返回不同类型结果集)

存储过程实例

CREATE PROCEDURE VariableResultShapes(@shape int)
AS
if(@shape = 1)
select CustomerID, ContactTitle, CompanyName from customers
else if(@shape = 2)
select OrderID, ShipName from orders

C# 存储过程代码

[Function(Name="dbo.VariableResultShapes")]
[ResultType(typeof(VariableResultShapesResult1))]
[ResultType(typeof(VariableResultShapesResult2))]
public IMultipleResults VariableResultShapes([Parameter(DbType="Int")] System.Nullable<int> shape)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), shape);
return ((IMultipleResults)(result.ReturnValue));
}

存储过程调用

IMultipleResults result = db.VariableResultShapes();

// Iterate through the list and write results (the company names)
// to the console.
foreach(VariableResultShapesResult1 compName in
result.GetResult<VariableResultShapesResult1>())
{
Console.WriteLine(compName.CompanyName);
} // Pause to view company names; press Enter to continue.
Console.ReadLine(); // Assign the results of the procedure with an argument
// of (2) to local variable 'result'.
IMultipleResults result2 = db.VariableResultShapes(); // Iterate through the list and write results (the order IDs)
// to the console.
foreach (VariableResultShapesResult2 ord in
result2.GetResult<VariableResultShapesResult2>())
{
Console.WriteLine(ord.OrderID);
}

最后说一句:其实就是很不要脸的把msdn上的东西拿过来了

参考:http://msdn.microsoft.com/zh-cn/library/system.data.linq.imultipleresults(v=vs.110).aspx

Linq to sql 接收存储过程返回的多个结果集的更多相关文章

  1. ASP.NET调用存储过程并接收存储过程返回值

    ASP.NET调用存储过程并接收存储过程返回值 2010-08-02 11:26:17|  分类: C#|字号 订阅       2010年02月27日 星期六 23:52 假设表结构Create T ...

  2. 关于linq to sql调用存储过程,出现"无法枚举查询结果多次"的问题

    DBML: [Function(Name="dbo.p_GetStudyStageSubjectGroup")] public ISingleResult<STUDYSTAG ...

  3. 最通用的ibatis.Net使用sql server存储过程返回分页数据的详细例子

    ibatis.Net是一个比较简单和灵活的ORM框架,今天我分享一个我的项目中使用sql server通用存储过程来分页的一个例子,用ibatis.Net框架统一返回分页数据为IList<Has ...

  4. C# 通过DataSet 获取SQL 存储过程返回的多个结果集(tables)

    测试数据:Northwind 链接地址: https://files.cnblogs.com/files/louiszh/NorthWind.zip 首先创建一个测试存储过程: IF EXISTS ( ...

  5. sql server存储过程返回数据只有一个字符

    SqlParameter[] param = { new SqlParameter("@shopId",shopId), new SqlParameter("@newSh ...

  6. 连接sqlServer数据库&jpa调用存储过程Java获取存储过程返回的多个结果集JAVA调用sqlserver存储过程的实现(返回多个结果集的实现)jdbc多结果集(getMoreResults)

    存储过程: BEGIN select * from teacher; SELECT * FROM student; END public Object GetMyBOProjectProductLis ...

  7. mybatis中用注解如何处理存储过程返回的多个结果集?

    sql代码: create procedure sptest.getnamesanditems() reads sql data dynamic result sets 2 BEGIN ATOMIC ...

  8. linq世界走一走(LINQ TO SQL)

    前言:作为linq的一个组件,同时作为ADO.NET的一个组成部分,LINQ TO SQL提供了将关系数据映射为对象的运行时基础结构. LINQ TO SQL是通过将关系数据库对象的数据模型(如一个数 ...

  9. C#获取存储过程返回值和输出参数值的方法

    //转自网络,先留个底 1.获取Return返回值 //存储过程 //Create PROCEDURE MYSQL // @a int, // @b int //AS // return @a + @ ...

随机推荐

  1. [连载]JavaScript讲义(04)--- 函数和闭包

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamFja2ZydWVk/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

  2. swift开发:试玩 Apple 站点的 playground

    https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/swift_programming_ ...

  3. WebBrowser 禁用脚本错误提示

    public partial class Text : UserControl {        public Text()        {                              ...

  4. 在Linux里设置环境变量的方法(export PATH)

    一般来说,配置交叉编译工具链的时候需要指定编译工具的路径,此时就需要设置环境变量.例如我的mips-linux-gcc编译器在“/opt/au1200_rm/build_tools/bin”目录下,b ...

  5. 网络IPC:套接字

    网络进程间通信(network IPC):不同计算机(通过网络相连)上运行的进程相互通信的机制. 套接字网络IPC接口:进程能够使用该接口和其他进程通信.通过该接口,其他进程运行位置是透明的,它们可以 ...

  6. C#_uploadify_mvc_version

    jQuery Uploadify在ASP.NET MVC3中的使用 1.Uploadify简介 Uploadify是基于jQuery的一种上传插件,支持多文件.带进度条显示上传,在项目开发中常被使用. ...

  7. c语言例子递归与整数逆序

    例一 #include <stdio.h> //将一整数逆序后放入一数组中(要求递归实现) void convert(int *result, int n) { if(n>=10) ...

  8. 双系统下,Windows如何正确删除Linux系统

    一般电脑装了双系统,特别是Windows加Linux的电脑,不可以在Windows中直接删了linux,因为一般安装linux的时候,grub都写进了mbr,直接删了Windows就进不了了,除非原来 ...

  9. Asp.Net 之 网页快照

    此文做法不是 Control.DrawToBitmap ,而是直接QueryInterface 浏览器Com对象的 IViewObject 接口,用它实现的Draw方法,画到图像上. 首先,定义IVi ...

  10. ie6双边距bug及其解决办法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...