Linq to sql 如何使用Linq to SQL从存储过程中检索返回值和结果集?

Linq to sql 如何使用Linq to SQL从存储过程中检索返回值和结果集?,linq-to-sql,stored-procedures,Linq To Sql,Stored Procedures,考虑这样一个存储过程: create procedure p1 as begin declare @n1 int; select @n1=count(*) from Employee; select top 100 * from Employee; return @n1; end 如何在C#中使用Linq To SQL捕获@n1以及员工结果集?您需要一个输出参数 create procedure p1(@n1 int =0 OUTPUT

考虑这样一个存储过程:

create procedure p1 as
begin
    declare @n1 int;
    select  @n1=count(*)
    from  Employee;

    select top 100 *
    from   Employee;
    return @n1;
end

如何在C#中使用Linq To SQL捕获
@n1
以及员工结果集?

您需要一个输出参数

create procedure p1(@n1 int =0 OUTPUT ) as
begin
    select 
       @n1=count(*)
    from
       Employee

    select top 100
        *
    from
        Employee
end
--请记住,当您执行proc时,您必须指示一个参数用于输出

Declare @val int
exec p1 @val OUTPUT

您需要一个输出参数

create procedure p1(@n1 int =0 OUTPUT ) as
begin
    select 
       @n1=count(*)
    from
       Employee

    select top 100
        *
    from
        Employee
end
--请记住,当您执行proc时,您必须指示一个参数用于输出

Declare @val int
exec p1 @val OUTPUT
已解决:

//I can access the resultset as following:
var emps = dataContext1.p1;

//I can get to @n1 by this:
int i1=int(emps).ReturnValue;
已解决:

//I can access the resultset as following:
var emps = dataContext1.p1;

//I can get to @n1 by this:
int i1=int(emps).ReturnValue;