1、使用dbml映射数据库,添加存储过程到dbml文件时报错。

2、原因:存储过程中使用了临时表

3、解决方案

3.1 通过自定义表值变量实现

Ex:

DECLARE @TempTable TABLE

(

AttributeID INT,

Value NVARCHAR(200)

)

INSERT INTO @TempTable Select * from Attribute

OR

--Execute SP and insert results into @TempTable

INSERT INTO @TempTable Exec GetAttribute @Id

You can do all operation which you was doing with #Temp table like Join, Insert, Select etc.

3.2  选中Db.dmbl文件--右键--新建--class文件--名称Db.cs,自定义partial class Db,写获取数据的方法,其中MyModel为你需要返回的数据model,Id为存储过程输入参数,存储过程名称为GetDataById(原名为[GetProjectsByClientId])

 public partial class Db {[global::System.Data.Linq.Mapping.FunctionAttribute(Name = "dbo.GetDataById")]public ISingleResult<MyModel> GetProjectsByClientId([global::System.Data.Linq.Mapping.ParameterAttribute(DbType = "NVarChar(10)")] string Id){IExecuteResult result = this.ExecuteMethodCall(this, ((System.Reflection.MethodInfo)(System.Reflection.MethodInfo.GetCurrentMethod())), Id);return ((ISingleResult<MyModel>)(result.ReturnValue));}}

调用: IList<MyModel> lst = db.GetDataById(id).ToList();

4、存储过程(进行了简化,理解意思即可)

IF object_id('GetDataById') IS NOT NULL
DROP PROCEDURE [dbo].[GetDataById]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

create procedure [dbo].[GetDataById]
 @clientId nvarchar(10)
 as
 begin
  SET NOCOUNT ON;
  IF object_id('tempdb..##tempProject') IS NOT NULL
        DROP TABLE ##tempProject
    
  select * into ##tempProject from Project where ClientId=@ClientId
  select p.id as ID,p.Name,a.Code,b.dtDate
           from ##tempProject p
        left join [dbo].[A] a on p.Id=a.ProjectId
        left join [dbo].[B] b on b.ProjectId=a.ProjectId
        
 end
GO

参考:

http://stackoverflow.com/questions/7035669/the-return-types-for-the-following-stored-procedures-could-not-be-detected

http://riteshkk2000.blogspot.com.au/2010/08/error-unknown-return-type-return-types.html

http://beyondrelational.com/modules/2/blogs/45/posts/12025/how-to-get-multiple-result-set-of-procedure-using-linq-to-sql.aspx

转载于:https://www.cnblogs.com/xiaochun126/p/4691529.html

The return types for the following stored procedures could not be detected相关推荐

  1. Calling Oracle stored procedures from Microsoft.NET

    摘自:http://www.c-sharpcorner.com/UploadFile/john_charles/CallingOraclestoredproceduresfromMicrosoftdo ...

  2. Spring, Hibernate and Oracle Stored Procedures

    一篇英文博文,写的是利用hibernate处理存储过程中的游标等等: Motivation: While there are a few resources available online for ...

  3. 自动备份SQL Server数据库中用户创建的Stored Procedures

    为了避免意外丢失/损坏辛苦创建的Stored Procedures,或者想恢复到以前版本的Stored Procedures,这样提供了一个有效方法,可以自动将指定数据库中的Stored Proced ...

  4. mysql stored procedures with return values

    存储过程的功能非常强大,在某种程度上甚至可以替代业务逻辑层, 接下来就一个小例子来说明,用存储过程插入或更新语句. 1.数据库表结构 所用数据库为Sql Server2008. 2.创建存储过程 (1 ...

  5. Trailing return types尾部返回类型

    文章目录 为什么要有尾部返回类型 什么是返回类型推导(return type deduction) 不是什么时候都要使用尾部返回类型   尾部返回类型在C++中是一个很奇怪的内容,我们应该只在必要的时 ...

  6. SQL Server :Stored procedures存储过程初级篇

    对于SQL Server,我是个拿来主义.很多底层的原理并不了解,就直接模仿拿着来用了,到了报错的时候,才去找原因进而逐步深入底层.我想,是每一次的报错,逼着我一点点进步的吧. 近期由于项目的原因,我 ...

  7. Method has to have one of the following return types

    如果方法参数传递了pageable,方法的返回值要求必须是Slice.List.Page,否则抛异常 如果你的方法返回值就是Slice.List.Page其中一种,查看你使用的类所在的包是不是spri ...

  8. Code First :使用Entity. Framework编程(7) ----转发 收藏

    第7章 高级概念 The Code First modeling functionality that you have seen so far should be enough to get you ...

  9. mysql-connector-java 属性介绍

    mysql-connector-java 属性介绍 5.1.48 版本 8.0.16 版本 备份一下, mysql 连接属性解释,想详细了解相关属性的可以 看看, LocalizedErrorMess ...

最新文章

  1. 计算机视觉一些项目实战技术(续)
  2. BIOS不识别linux,linux – 在BIOS中启用VT但KVM无法检测到
  3. DialogFragment源码分析
  4. SpringSecurity +Jwt 实现权限管理
  5. 腾讯公司被法院强制执行25元,刚好是QQ超级会员的价格
  6. java学生签到系统_学生签到系统.pdf
  7. OSI第三层:网络层功能及作用OSI第三层:网络层功能及作用
  8. NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
  9. NATAPP vscode SSH远程连接Linux服务器出现couldn‘t establish connection
  10. h5+js+ajax+百度翻译API:实现翻译功能
  11. 净误差与遗漏为负值的含义_【双语】跳出“资本外逃”之争看净误差与遗漏
  12. 高中数学公式必背的50条秒杀技巧(学霸必备)
  13. 斗地主手牌(水贴ψ(*`ー´)ψ)
  14. 有哪些不错的电子书管理软件?免费项目管理软件推荐
  15. python列表sort倒序输出_Python 列表sort()添加key和reverse参数操作方法|python基础教程|python入门|python教程...
  16. 向windows服务器传输大文件时提示未知错误解决方法
  17. 云主机服务比价与预测系统开发心得--第一周(1)--git技术
  18. node安装详细步骤
  19. Matlab矩阵基本操作(定义,运算)
  20. 轩小陌的Python笔记-day05 数据类型

热门文章

  1. [原]RHCS集群的服务切换测试札记
  2. css --- [小结]让盒子水平垂直居中的解决方案
  3. [译] 前端组件设计原则
  4. 关于SpringCloud、SpringBoot 希望这是说得最详细的
  5. eclipse maven jetty插件方式启动项目
  6. 罗伯特·帕丁森Robert Pattinson(2)
  7. 20150901-Linux磁盘管理及文件系统管理
  8. 海尔5D净水洗热水器引领中国制造未来
  9. apache+php32位平台安装
  10. GPU 与CPU的作用协调,工作流程、GPU整合到CPU得好处