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 + @ ...
随机推荐
- Android线程和线程池
Translated From Google Android. class PhotoDecodeRunnable implements Runnable {... /* * Defin ...
- AS3 Signals
在项目中,使用as3内置事件框架必须通过自定义事件才可以实现值的传递,大量自定义事件.定义常量和整个事件派发的管理.添加侦听器.移除侦听器,或多或少都会带来大量的代码,而signals这个框架思想原来 ...
- TFS服务器(微软源代码管理服务器)上彻底删除项目
在TFS服务器上建立了很多项目,发现在Team Explorer中,只能移除团队项目,这种移除,只是将项目从当前Team Explorer项目列表中删除,下一次Connect到TFS服务器时,或者刷新 ...
- SQL Server中内连接和外连接的区别
SQL Server中内连接和外连接的区别 假设一个数据库中有两张表,一张是学生表StudentInfo,一张是班级表ClassInfo,两张表之间用ClassId字段进行关联. 如果用内连接,正常的 ...
- python分页和session和计算时间差
分页 #!/usr/bin/env python # -*- coding:utf-8 -*- class Pagenation: def __init__(self,current_page,all ...
- Android(java)学习笔记107-0:通过反射获得构造方法并且使用
1.获取字节码文件对象: Class c = Class.forName("cn.itcast_01.Person"); 2.获取构造方法 ...
- Log4Net之初步了解
原创文章,转载必需注明出处:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/log4net%E4%B9%8B%E5%88%9D%E6 ...
- jfreechart的使用案例
一:下载需要的2个jar文件 jcommon-版本号.jar,jfreechart-版本号.jar,注意版本不要太高. 实例一:比较简单的application版本的饼图 /** * */ packa ...
- 一些网摘的hpc材料
source from: https://computing.llnl.gov Factors determines a large-scale program's performance 4 ...
- Global.asax中的操作数据库代码无法执行
本人最近在做一个基于Access数据库的Web应用程序,为了实现一个定时更新数据库的需求,我在Global.asax中的Application_Start函数里写了个计时器, void Applica ...