• 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()

  • 相关阅读:
    UVA1599 理想路径 Ideal Path(最短路径)
    换根DP
    小w的魔术扑克(树状数组+并查集)
    NOIP 2016蚯蚓(优先队列)
    ZR 动物园
    T105017 seq(DP)
    noip2017酱油记
    noip2017酱油记前篇
    P1985 翻转棋
    luogu P2512 [HAOI2008]糖果传递
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749082.html
Copyright © 2020-2023  润新知