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

一、返回顺序结果集

存储过程实例

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

最新文章

  1. MAC下彻底解决mysql无法插入和显示中文
  2. php--validate表单验证
  3. uml类关系
  4. [linux] linux下编译安装zlib
  5. 多屏判断css改写
  6. How to use Android Activity&#39;s finish(), onDestory() and System.exit(0) methods
  7. php网页显示正方形图片缩略图
  8. 让DataGridView显示行号
  9. for循环删除集合陷阱
  10. 在C#环境中动态调用IronPython脚本(二)
  11. BZOJ 2038: [2009国家集训队]小Z的袜子(hose) 分块
  12. js两个判断&amp;&amp;的值与||的值
  13. 【转载】CANoe 入门 Step by step系列(二)CAPL编程
  14. webpack 简单配置
  15. opencv常用api
  16. 分布式全文检索引擎之ElasticSearch
  17. SpringBoot thymeleaf使用方法,thymeleaf模板迭代
  18. mysql更新(四) 数据类型
  19. input:checkbox 是否被选中?
  20. Java设计模式(10)——结构型模式之代理模式(Proxy)

热门文章

  1. [AngularJS] ngModelController render function
  2. juggle
  3. perl详解
  4. XCode中调整字体大小
  5. xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot;,这是什么意思,我只知道:xmlns:xx=....,
  6. MapReduce中使用SequenceFile的方式上传文件到集群中
  7. 24小时学通Linux内核--内核探索工具类
  8. 运用NPOI操作EXCEL
  9. C# 计算文件的 Hash 值
  10. 【转】预编译头文件来自编译器的早期版本,或者预编译头为 C++ 而在 C 中使用它(或相反)