zoukankan      html  css  js  c++  java
  • 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()

  • 相关阅读:
    MSSQL查询表占用空间
    JS字典
    匹配是否指定主域名
    站点文件删除不了提示权限不足
    事件委托发布-订阅
    微信中打开第三方应用
    以Spring Bean配置文件为例解释 xmlns,xmlns:xsi,xsi:schemaLocation
    Hdfs的读出机制
    Hdfs的写入机制
    spring常用注解的作用
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749082.html
Copyright © 2011-2022 走看看