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. 如何在natTable表格上添加双击事件

    在项目当中,有时候需要双击表格中的某一行触发一个事件或者一次数据请求,这时候,我们就需要在表格中绑定相关事件,思路实际上很简单,添加一个绑定事件就ok了,那么怎么添加呢?简单实现如下: 1.创建绑定双 ...

  2. Fiddler抓包9-保存会话(save)【转载】

    本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/tag/fiddler/ 前言 为什么要保存会话呢?举个很简单的场景,你在上海测试某个功能接口的 ...

  3. Ubuntu14.04 在右键中添加 在终端中打开

    1.在terminal中执行: sudo apt-get install nautilus-open-terminal 此时可能会提示:nable to locate package nautilus ...

  4. POJ 3041.Asteroids-Hungary(匈牙利算法)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23963   Accepted: 12989 Descr ...

  5. Codeforces Round #277.5 (Div. 2) B. BerSU Ball【贪心/双指针/每两个跳舞的人可以配对,并且他们两个的绝对值只差小于等于1,求最多匹配多少对】

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. servlet之request

    1. request的setAttribute与getAttribute方法一般都是成对出现的,首先通过setAttribute方法设置属性与属性值,然后通过getAttribute方法根据属性获取到 ...

  7. 前端中 width 的获取

    这篇文章其实是在了解 viewport 的过程中发现这些概念容易混淆做了个小小的总结.viewport的首要关键是宽度的获取,宽度的计算有下面几个属性和方法: clientWidth offsetWi ...

  8. 【bzoj3261】【最大异或和】可持久化trie树+贪心

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=61705397 Description 给定一个非 ...

  9. [置顶] 使用kube-proxy让外部网络访问K8S service的ClusterIP

    配置方式 kubernetes版本大于或者等于1.2时,外部网络(即非K8S集群内的网络)访问cluster IP的办法是: 修改master的/etc/kubernetes/proxy,把KUBE_ ...

  10. 如何使用apache的 work模式还是 prefork 模式

    注意: 2.4之前版本默认为prefork, 2.4已经变为event模式.三种模式比较: http://www.cnblogs.com/fnng/archive/2012/11/20/2779977 ...