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

The return types for the following stored procedures could not be detected的更多相关文章

  1. [MySQL] Stored Procedures 【转载】

    Stored routines (procedures and functions) can be particularly useful in certain situations: When mu ...

  2. Good Practices to Write Stored Procedures in SQL Server

    Reference to: http://www.c-sharpcorner.com/UploadFile/skumaar_mca/good-practices-to-write-the-stored ...

  3. An Introduction to Stored Procedures in MySQL 5

    https://code.tutsplus.com/articles/an-introduction-to-stored-procedures-in-mysql-5--net-17843 MySQL ...

  4. Cursors in MySQL Stored Procedures

    https://www.sitepoint.com/cursors-mysql-stored-procedures/ After my previous article on Stored Proce ...

  5. MySQL Error Handling in Stored Procedures 2

    Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...

  6. Why Stored Procedures?

    http://www.w3resource.com/mysql/mysql-procedure.php Stored procedures are fast. MySQL server takes s ...

  7. Part 10 Stored procedures in sql server

    Stored procedures in sql server Stored procedures with output parameters Stored procedure output par ...

  8. [转]Oracle Stored Procedures Hello World Examples

    本文转自:http://www.mkyong.com/oracle/oracle-stored-procedures-hello-world-examples/ List of quick examp ...

  9. [转]How to: Execute Oracle Stored Procedures Returning RefCursors

    本文转自:http://www.telerik.com/help/openaccess-orm/openaccess-tasks-oracle-execute-sp-result-set.html I ...

随机推荐

  1. JavaScript学习总结-技巧、实用函数、简洁方法、编程细节

    整理JavaScript方面的一些技巧,比较实用的函数,常见功能实现方法,仅作参考 变量转换 var myVar = "3.14159", str = ""+ ...

  2. POJ 3225.Help with Intervals-线段树(成段替换、区间异或、简单hash)

    POJ3225.Help with Intervals 这个题就是对区间的各种操作,感觉这道题写的一点意思都没有,写到后面都不想写了,而且更神奇的是,自己的编译器连结果都输不出来,但是交上就过了,也是 ...

  3. HDU 1074 Doing Homework(状压DP)

    第一次写博客ORZ…… http://acm.split.hdu.edu.cn/showproblem.php?pid=1074 http://acm.hdu.edu.cn/showproblem.p ...

  4. @Transactional注解事务不起作用

    @Transactional注解事务不起作用 问题:今天在项目中碰到一个事务问题,使用@Transactional注解事务,抛出异常不会滚. 解决一:https://blog.csdn.net/u01 ...

  5. [Usaco2010 Nov]Visiting Cows

    题目描述 经过了几周的辛苦工作,贝茜终于迎来了一个假期.作为奶牛群中最会社交的牛,她希望去拜访N(1<=N<=50000)个朋友.这些朋友被标号为1..N.这些奶牛有一个不同寻常的交通系统 ...

  6. ORA-17129=SQL 字符串不是DML 语句

    ORA-17129=SQL 字符串不是DML 语句 oracle这个错误的意思是 select 不可以算DML 数据操纵语言(Data Manipulation Language, DML)是SQL语 ...

  7. Flatten 2D Vector -- LeetCode

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [,], [], [,,] ] By cal ...

  8. [BZOJ 3108] 图的逆变换

    Link: BZOJ 3108 传送门 Solution: 样例教你做题系列 观察第三个输出为No的样例,发现只要存在$edge(i,k),edge(j,k)$,那么$i,j$的出边一定要全部相同 于 ...

  9. 远程访问CENTOS的MYSQL数据库设置

    远程访问CENTOS的MYSQL数据库设置 mysql -u root grant all privileges on *.* to root@'%'identified by 'root'; 后面的 ...

  10. ASP.NET 5 简介

    来源https://docs.asp.net/en/latest/conceptual-overview/aspnet.html ASP.NET 5 是ASP.NET的重新设计. 什么是ASP.NET ...