• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

我们将共同携手迎接你的到来!


新的一年
新的开始
新的目标
新的收获

kevin 愛戀 20140103

博客园          联系   管理     
Linq to sql(五):存储过程(三)
2010年05月11日 星期二 16:06

多结果集的存储过程

       再来创建一个多结果集的存储过程:

create proc [dbo].[sp_multiresultset]

as

set nocount on

select * from customers

select * from employees

       找到生成的存储过程方法:

[Function(Name="dbo.sp_multiresultset")]

    public ISingleResult<sp_multiresultsetResult> sp_multiresultset()

    {

        IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));

        return ((ISingleResult<sp_multiresultsetResult>)(result.ReturnValue));

    }

       由于现在的VS2008会把多结果集存储过程识别为单结果集存储过程(只认识第一个结果集),

我们只能对存储过程方法多小动手术,修改为:

    [Function(Name="dbo.sp_multiresultset")]

    [ResultType(typeof(Customer))]

    [ResultType(typeof(Employee))]

    public IMultipleResults sp_multiresultset()

    {

        IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));

        return (IMultipleResults)(result.ReturnValue);

    }

       然后使用下面的代码测试:

        var 多结果集存储过程 = ctx.sp_multiresultset();

        var Customers = 多结果集存储过程.GetResult<Customer>();

        var Employees = 多结果集存储过程.GetResult<Employee>();

        GridView1.DataSource = from emp in Employees where emp.FirstName.Contains("A") select emp;

        GridView1.DataBind();

        GridView2.DataSource = from c in Customers where c.CustomerID.StartsWith("A") select c;

        GridView2.DataBind()

posted on 2010-06-01 13:33  kevin_20131022  阅读(230)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3