首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • LINQ中,调用分页存储过程时,出现的问题。 [已结贴,结贴人:pt1314917]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-06 10:43:04 楼主
      将存储过程拖进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这种吗?
    100  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-06 10:55:511楼 得分:0
    奇怪。也不全是动态SQL的问题。我试了这样的存储过程。
    SQL code
    create proc ppp as exec('select * from sub')

    却又可以哦。。
    而这种又不行。
    SQL code
    ---按类别显示帖子(分页) ALTER proc Page_CountSort (@Table varchar(50), --表名 @Filter varchar(1000),--返回字段:用','隔开 @Count int, --每页显示记录数 @id varchar(50), --用来排序的ID @CurrPage int, --当前页数 @sortid int --类别 ) as declare @Sql varchar(8000) if(@CurrPage=1) begin set @Sql='select top '+ cast(@Count as varchar) + ' '+ @Filter + ' from ' + @Table + ' where isnull(isback,1)=0 and Sortid=' + cast(@sortid as varchar) + ' order by case when ispublic=1 then 1 when istop=1 then 2 else 3 end,toptime desc,lastback desc' end else begin set @Sql='select top '+ cast(@Count as varchar) + ' '+ @Filter + ' from ' + @Table + ' where isnull(isback,1)=0 and ' + @id + ' not in (select top '+ cast((@CurrPage-1)*@Count as varchar) + ' ' + @id + ' from ' + @Table + ' where isnull(isback,1)=0 and Sortid='+ cast(@sortid as varchar) +' order by case when ispublic=1 then 1 when istop=1 then 2 else 3 end,toptime desc,lastback desc) and Sortid=' + cast(@sortid as varchar) + ' order by case when ispublic=1 then 1 when istop=1 then 2 else 3 end,toptime desc,lastback desc' end EXEc(@Sql)

    这种却调用不了。返回类型总是int,就算我增加一个对应的Result类,改了返回类型。重新生成一下。又还原了。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-06 10:56:122楼 得分:25
    友情up
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-06 11:18:183楼 得分:0
    找到问题之所在了。原来是因为在分页存储过程中,我将表名作为变量传进去的,所以.net在存储过程中找不到表名,无法生成那个类了。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-06 11:27:044楼 得分:0
    上面错了。经过多次实验,发现只要动态SQL中包含变量。即:
    SQL code
    create proc sss @where varchar(100) as exec('select * from 表名 '+@where)


    这种形式的都不行。看来LINQ TO SQL还不够完善啊。。。。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • dapanda
    • 等级:
    发表于:2008-06-17 12:25:225楼 得分:25
    我碰到的问题好一样,我在dao增加了一个getpage的方法,代码返回dataset,不调用linq,也用得挺好的啊。虽然没有测试过,但是我觉得速度肯定会快很多。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-18 09:23:166楼 得分:25
    友情up友情up友情up
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    发表于:2008-06-18 13:35:347楼 得分:25
    占位符

    回复内容太短了!
    回复内容太短了!
    修改 删除 举报 引用 回复

    网站简介广告服务网站地图帮助联系方式诚聘英才English 问题报告
    北京创新乐知广告有限公司 版权所有 京 ICP 证 070598 号
    世纪乐知(北京)网络技术有限公司 提供技术支持
    Copyright © 2000-2008, CSDN.NET, All Rights Reserved