简体   繁体   English

无法检测到存储过程返回类型

[英]Stored Procedure Return Type Can Not Be Detected

I am trying to drag this procedure over to the dbml in VS 2012 and I am getting the return type cannot be detected message.我正在尝试将此过程拖到 VS 2012 中的 dbml 中,但我收到了无法检测到返回类型的消息。

I have tried these: LINQ to SQL - Stored Procedure Return Type Error The return types for the following stored procedures could not be detected我已经尝试过这些: LINQ to SQL - 存储过程返回类型错误无法检测到以下存储过程的返回类型

I tried re-writing the procedure as a CTE and also as union to remove the OR, but it is giving me the same message.我尝试将程序重新编写为 CTE 和联合以删除 OR,但它给了我相同的信息。

The only return type in the designer properties for the method is int32.该方法的设计器属性中唯一的返回类型是 int32。

Here is my procedure:这是我的程序:

ALTER PROCEDURE [dbo].[GetStringFromFiles]
    @SearchWord NVARCHAR(100) = null
AS
BEGIN

    SET NOCOUNT ON
    SET @SearchWord = UPPER(@SearchWord);

Select    
       a.FileId     <---Guid
     , a.FileData   <---Binary
     , a.BaselineId <---Guid
     , a.FileName   <---NVARCHAR
     , a.FileExtension  <---NVARCHAR
     , b.FileByItemId   <----Guid
     , b.ItemId   <---Guid
From FileTable a

    Inner Join

     FileByItem b on a.FileId = b.FileId 

     WHERE CONTAINS(a.FileData,'FORMSOF(INFLECTIONAL, @SearchWord)') or FREETEXT(a.FileData, @SearchWord)
    RETURN 1
END

UPDATE:更新:

A. I can add it if I comment out the entire Where Clause -- Auto-Generated-ReturnType A. 如果我注释掉整个 Where 子句 -- Auto-Generated-ReturnType,我可以添加它

B. If I take away the or and just use: B. 如果我拿走 or 直接使用:

WHERE CONTAINS(a.FileData,'FORMSOF(INFLECTIONAL, @SearchWord)')

it lets me add it -- Auto-Generated-ReturnType它让我添加它 -- Auto-Generated-ReturnType

C. If I just use C. 如果我只是使用

WHERE FREETEXT(a.FileData, @SearchWord)

It throws the error so it doesnt like the FREETEXT它抛出错误,所以它不喜欢 FREETEXT

If I comment the where clause out and add it and let it generate the return type then alter the procedure in the db are there any issues with that?如果我将 where 子句注释掉并添加它并让它生成返回类型然后更改数据库中的过程是否有任何问题?

This is somewhat related.这有点关系。 I stumbled across the same error today but for a different reason.我今天偶然发现了同样的错误,但原因不同。 If your query uses a temporary table in its results then it is unable to automatically assign the return type.如果您的查询在其结果中使用临时表,则无法自动分配返回类型。

I changed it to a table variable (performance was not a major concern/and was not impacted)我将其更改为表变量(性能不是主要问题/并且没有受到影响)

Hope this helps someone browsing.希望这有助于有人浏览。

The line线

RETURN 1

is the culprit in both the cases.是这两种情况的罪魁祸首。 Lose it and Linq should be able to detect the types your result set.失去它,Linq 应该能够检测到您的结果集的类型。

Linq to Sql won't get the results directly from a Stored procedure. Linq to Sql 不会直接从存储过程中获取结果。 Instead an ISingleResult will be returned.相反,将返回 ISingleResult。 You have to enumerate through the result set to get the values returned from the stored procedure您必须通过结果集进行枚举以获取从存储过程返回的值

If the stored procedure have any error also then this error can occur, for me its happened once since one of the table name was changed.如果存储过程也有任何错误,则可能会发生此错误,对我而言,自从更改表名之一以来,它发生过一次。

Another factor is to set Primary Keys and table relations if possible另一个因素是如果可能的话设置主键和表关系

A simple way to solve this issue is (December 2019)解决此问题的一个简单方法是(2019 年 12 月)

  • Just making double # precede #tmp => ##tmp只是在#tmp 之前加上双# => ##tmp
  • Comment out DROP TABLE #tmp => --DROP TABLE #tmp注释掉 DROP TABLE #tmp => --DROP TABLE #tmp
  • Execute stored procedure执行存储过程
  • Drag stored procedure again and That's it, It will generate return type再次拖动存储过程就这样,它会生成返回类型
  • Last, Turn your store back to the first situation and then save.最后,将您的商店恢复到第一种情况,然后保存。

Hope I can help.希望我能帮上忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM