日期:2014-05-20  浏览次数:20729 次

LINQ中,调用分页存储过程时,出现的问题。
将存储过程拖进dbml文件时,其designer.cs文件会自动生成如下代码:
C# code

        [Function(Name="dbo.Page_CountSort")]
        public int Page_CountSort([Parameter(Name="Table", DbType="VarChar(50)")] string table, [Parameter(Name="Filter", DbType="VarChar(1000)")] string filter, [Parameter(Name="Count", DbType="Int")] System.Nullable<int> count, [Parameter(DbType="VarChar(50)")] string id, [Parameter(Name="CurrPage", DbType="Int")] System.Nullable<int> currPage, [Parameter(DbType="Int")] System.Nullable<int> sortid)
        {
            IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), table, filter, count, id, currPage, sortid);
            return ((int)(result.ReturnValue));
        }


可问题是,我这个分页存储过程返回类型并不是int,而是记录集的。我重新拖进来一个比较简单的存储过程,
如存储过程是这样的,
SQL code
create proc lll 
as 
select * from tablename


它生成的代码就不一样,就会是:
C# code
[Function(Name="dbo.lll")]
        public ISingleResult<lllResult> lll()
        {
            IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
            return ((ISingleResult<lllResult>)(result.ReturnValue));
        }

下面还有个lllResult类。为什么我的分页存储过程不能生成这样的呢?
我试着把分页存储过程也增加了一个Page_CountSortResult类,并将上面的方法返回类型修改了。但重新生成后。又被还原了。

难道LINQ调用的存储过程中不能是动态SQL这种吗?

------解决方案--------------------
友情up
------解决方案--------------------
我碰到的问题好一样,我在dao增加了一个getpage的方法,代码返回dataset,不调用linq,也用得挺好的啊。虽然没有测试过,但是我觉得速度肯定会快很多。
------解决方案--------------------
友情up友情up友情up
------解决方案--------------------
占位符

回复内容太短了!
回复内容太短了!