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

  • 相关阅读:
    【Codechef】Chef and Bike(二维多项式插值)
    USACO 完结的一些感想
    USACO 6.5 Checker Challenge
    USACO 6.5 The Clocks
    USACO 6.5 Betsy's Tour (插头dp)
    USACO 6.5 Closed Fences
    USACO 6.4 Electric Fences
    USACO 6.5 All Latin Squares
    USACO 6.4 The Primes
    USACO 6.4 Wisconsin Squares
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749082.html
Copyright © 2011-2022 走看看