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

最新文章

  1. &lt;!DOCTYPE html&gt;很重要
  2. mssql 小技巧
  3. [JWFD开源工作流]JWFD开源工作流官方下载内容更新
  4. Educational Codeforces Round 4 B. HDD is Outdated Technology 暴力
  5. PHP 中mysql如何实现事务提交?
  6. Winform Textbox实现滚动条始终在最下面
  7. Git 笔记二-Git安装与初始配置
  8. Windows下搭建HTTP/HTTPS服务器及测试过程
  9. ES6新属性笔记
  10. R语言生成随机数
  11. HDU 4291 A Short problem(矩阵+循环节)
  12. [POI2007]ZAP-Queries
  13. Intellij idea使用过程中遇到的一些问题
  14. Excel中的数据与DataSet的互换
  15. L1-056 猜数字
  16. Linux远程批量工具mooon_ssh和mooon_upload使用示例
  17. android(七)Looper Handler分析
  18. 「不定期更新」MacOS 编辑器使用小技巧
  19. ORA-01919: role &#39;OLAPI_TRACE_USER&#39; does not exist
  20. 在Eclipse中导入新浪微博SDK

热门文章

  1. (一)使用sklearn做各种回归
  2. hdu 5086(递推)
  3. web前端到底是什么?有前途吗
  4. linux安装mongodb(设置非root用户和开机启动)
  5. String format -1 常规格式化
  6. 开始使用 Docker (Linux 上运行 SQL Server) 上的 SQL Server 容器 - SQL Server | Microsoft Docs
  7. Facebook KeyHash生成方法
  8. UVa 407
  9. python xml与字典的相互转换
  10. 机器学习第1课:引言(Introduction)