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

  • 相关阅读:
    vue实战使用ajax请求后台数据(小白)
    jQuery实现tab栏切换效果
    jQuery下的ajax实例
    数据库之视图更新
    SQL Server 全文索引创建
    SQL Server 分区表
    数据快照 (Database Snapshot)
    FileStream
    ODBC,OLEDB,ADO,ADO.net,JDBC 理解
    拖延症?贪玩?来试试"百万金币时间管理法"
  • 原文地址:https://www.cnblogs.com/kevin2013/p/1749082.html
Copyright © 2011-2022 走看看