读书人

Linq to SQL怎么既返回结果集 又outpu

发布时间: 2012-03-04 11:13:33 作者: rapoo

Linq to SQL如何既返回结果集 又output参数和returnValue啊

SQL code
USE [WebStore]GO/****** Object:  StoredProcedure [dbo].[getdataset]    Script Date: 12/08/2009 11:16:05 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER proc [dbo].[getdataset]@TableList Varchar(max)='*',--搜索表的字段,比如:’id,datatime,job‘,用逗号隔开@TableName Varchar(max), --搜索的表名@SelectWhere NVarchar(max)='',--搜索条件,这里不用写where,比如:job=’teacher‘and class='2'@SelectOrderId Varchar(200),--表主键字段名。比如:id@SelectOrder Varchar(200)='', --排序,可以使用多字段排序但主键字段必需在最前面.也可以不写,比如:order by class asc@intPageNo int=1, --页号@intPageSize int=10 ,--每页显示数@RecordCount int OUTPUT  --总记录数(存储过程输出参数)as      declare @TmpSelect      NVarchar(max)  declare @Tmp     NVarchar(max)  set nocount on--关闭计数if @SelectWhere !=''beginset @TmpSelect = 'select @RecordCount = count(*) from '+@TableName+' where '+@SelectWhereendelsebeginset @TmpSelect = 'select @RecordCount = count(*) from '+@TableNameendexecute sp_executesql @TmpSelect,    --执行上面的sql语句N'@RecordCount int OUTPUT' ,   --执行输出数据的sql语句,output出总记录数@RecordCount  OUTPUT  if (@RecordCount = 0)    --如果没有贴子,则返回零       return 0          /*判断页数是否正确*/  if (@intPageNo - 1) * @intPageSize > @RecordCount   --页号大于总页数,返回错误     return (-1)set nocount off--打开计数if @SelectWhere != '' beginset @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' where '+@SelectWhere +' '+@SelectOrder+') and '+@SelectWhere +' '+@SelectOrderendelsebeginset @TmpSelect = 'select top '+str(@intPageSize)+' '+@TableList+' from '+@TableName+' where '+@SelectOrderId+' not in(select top '+str((@intPageNo-1)*@intPageSize)+' '+@SelectOrderId+' from '+@TableName+' '+@SelectOrder+') '+@SelectOrderendexecute sp_executesql @TmpSelectreturn(@@rowcount)


我现在只输出output 我还要select top的结果集,请高手解答啊

[解决办法]
LINQ自动产生的存储过程默认的返回结果是ISingleResult,你需要手工修改它产生的方法,将它的返回结果改为IMultiResult,并且在那方法中,对你的返回结果进行处理。

读书人网 >.NET

热点推荐