Linq to sql 接收存储过程返回的多个结果集
故事前提。。。。。。。。。。
一、返回顺序结果集
存储过程实例
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 接收存储过程返回的多个结果集的更多相关文章
- ASP.NET调用存储过程并接收存储过程返回值
ASP.NET调用存储过程并接收存储过程返回值 2010-08-02 11:26:17| 分类: C#|字号 订阅 2010年02月27日 星期六 23:52 假设表结构Create T ...
- 关于linq to sql调用存储过程,出现"无法枚举查询结果多次"的问题
DBML: [Function(Name="dbo.p_GetStudyStageSubjectGroup")] public ISingleResult<STUDYSTAG ...
- 最通用的ibatis.Net使用sql server存储过程返回分页数据的详细例子
ibatis.Net是一个比较简单和灵活的ORM框架,今天我分享一个我的项目中使用sql server通用存储过程来分页的一个例子,用ibatis.Net框架统一返回分页数据为IList<Has ...
- C# 通过DataSet 获取SQL 存储过程返回的多个结果集(tables)
测试数据:Northwind 链接地址: https://files.cnblogs.com/files/louiszh/NorthWind.zip 首先创建一个测试存储过程: IF EXISTS ( ...
- sql server存储过程返回数据只有一个字符
SqlParameter[] param = { new SqlParameter("@shopId",shopId), new SqlParameter("@newSh ...
- 连接sqlServer数据库&jpa调用存储过程Java获取存储过程返回的多个结果集JAVA调用sqlserver存储过程的实现(返回多个结果集的实现)jdbc多结果集(getMoreResults)
存储过程: BEGIN select * from teacher; SELECT * FROM student; END public Object GetMyBOProjectProductLis ...
- mybatis中用注解如何处理存储过程返回的多个结果集?
sql代码: create procedure sptest.getnamesanditems() reads sql data dynamic result sets 2 BEGIN ATOMIC ...
- linq世界走一走(LINQ TO SQL)
前言:作为linq的一个组件,同时作为ADO.NET的一个组成部分,LINQ TO SQL提供了将关系数据映射为对象的运行时基础结构. LINQ TO SQL是通过将关系数据库对象的数据模型(如一个数 ...
- C#获取存储过程返回值和输出参数值的方法
//转自网络,先留个底 1.获取Return返回值 //存储过程 //Create PROCEDURE MYSQL // @a int, // @b int //AS // return @a + @ ...
随机推荐
- js获取网络图片的宽和高
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【ZZ】MySql语句大全:创建、授权、查询、修改等
http://blog.csdn.net/evankaka/article/details/45580845
- PHP做好防盗链的基本思想 防盗链的设置方法
盗链是指服务提供商自己不提供服务的内容,通过技术手段绕过其它有利益的最终用户界面(如广告),直接在自己的网站上向最终用户提供其它服务提供商的服务内容,骗取最终用户的浏览和点击率.受益者不提供资源或提供 ...
- TortoiseGit安装和使用的图文教程
ortoiseGit是Windows下不错的一款Git客户端工具,在Mac下推荐使用sourcetree.下面就介绍一下TortoiseGit安装和使用的方法. 安装TortoiseGit并使用它需要 ...
- kafka彻底删除topic
如果只是用kafka-topics.sh的delete命令删除topic,会有两种情况: 如果当前topic没有使用过即没有传输过信息:可以彻底删除 如果当前topic有使用过即有过传输过信息:并没有 ...
- Android 定时器实现的几种方式和removeCallbacks失效问题详解
实现定时器有很多种方式,在这里我简单的介绍几种方式 (1)使用Handler + Runnable的方式 Handler handler = new Handler(); Runnable runna ...
- 琐碎-关于hadoop的GenericOptionsParser类
GenericOptionsParser 命令行解析器 是hadoop框架中解析命令行参数的基本类.它能够辨别一些标准的命令行参数,能够使应用程序轻易地指定namenode,jobtracker,以及 ...
- Java基础知识强化103:Java常量池理解与总结
一.相关概念 1. 什么是常量 用final修饰的成员变量表示常量,值一旦给定就无法改变! final修饰的变量有三种:静态变量.实例变量和局部变量,分别表示三种类型的常量. 2. Class文件中的 ...
- oracle数据字典和动态性能视图
数据字典和动态性能视图数据字典是oracle数据库中重要的组成部分,提高了数据库的一些系统信息.(静态信息)动态性能视图记载了例程启动后的信息.(动态信息) 数据字典记录了数据的系统信息,是只读表和动 ...
- spring-boot配置外部静态资源的方法
import java.io.File; import javax.servlet.Servlet; import lombok.extern.slf4j.Slf4j; import org.spri ...