Linq to sql 无法检测到以下存储过程的返回类型

Linq to sql 无法检测到以下存储过程的返回类型,linq-to-sql,Linq To Sql,在dbml文件中拖放存储过程时,我遇到以下错误: 未知返回类型 无法检测到以下存储过程的返回类型。在“属性”窗口中为每个存储过程设置返回类型 如何解决此错误?每当设计人员无法确定SP的返回类型时,就会出现此问题。 描述了相同的问题和解决方案 如何使用 基本上,这是链接的解决方案: 避免在存储过程中使用temp Table,而可以使用如下@TENTABLE这样的表类型变量 例: 您可以使用Temp表执行所有操作,如 加入、插入、选择等 原因:存储过程将返回复杂类型。也就是说,多个结果或使用一个临时

在dbml文件中拖放存储过程时,我遇到以下错误:

未知返回类型 无法检测到以下存储过程的返回类型。在“属性”窗口中为每个存储过程设置返回类型


如何解决此错误?

每当设计人员无法确定SP的返回类型时,就会出现此问题。 描述了相同的问题和解决方案 如何使用

基本上,这是链接的解决方案:

避免在存储过程中使用temp Table,而可以使用如下@TENTABLE这样的表类型变量

例:

您可以使用Temp表执行所有操作,如 加入、插入、选择等


原因:存储过程将返回复杂类型。也就是说,多个结果或使用一个临时表

决议

这完全取决于存储过程在做什么。有用的链接


我也有这个问题-必须注释掉正在构造多边形的代码:

declare
    @MapBounds geography
    ;

select
    @MapBounds = geography::STGeomFromText('POLYGON((' + 
        cast(@NorthEastLng as varchar) + ' ' + cast(@NorthEastLat as varchar) + ', ' +  
        cast(@SouthWestLng as varchar) + ' ' + cast(@NorthEastLat as varchar) + ', ' +  
        cast(@SouthWestLng as varchar) + ' ' + cast(@SouthWestLat as varchar) + ', ' +  
        cast(@NorthEastLng as varchar) + ' ' + cast(@SouthWestLat as varchar) + ', ' + 
        cast(@NorthEastLng as varchar) + ' ' + cast(@NorthEastLat as varchar) + 
        '))', 4326)
    ;

一旦它被添加到dmbl中,我就取消了对代码的注释,它就像冠军一样工作

万一有人遇到这种情况,我自己也经历过

在我的例子中,我引用了模式中不再存在的insert语句中的一个表。仔细检查我的代码发现我正在插入一个名为Account的表,该表现在名为tblAccount。VisualStudio在保存sp时没有抛出错误,但我在尝试将sp添加到dbml文件时遇到了相同的错误


希望这能帮助其他人解决问题。

这也可能是访问权限的问题。如果存储过程不能访问该表,则会出现相同的错误。我有一个从另一个数据库中选择数据的查询,我没有权限,事实上运行VisualStudio连接的帐户没有权限,我收到了相同的错误。加上适当的权利后,一切都很顺利


在服务器资源管理器中右键单击并选择“执行”,尝试在VS2010中执行存储过程,这有助于我解决此问题。

我在SQL中使用了一个临时表,因此出现了此错误。我将临时表转换为表变量,并解决了我的问题。

您不妨考虑使用CONTAT方法而不是“+”来勾结字符串。因为我没有使用临时表,但仍然遇到这个问题。我发现使用“+”对字符串进行concating会触发此操作

就我而言,我使用的是:

SET @errorMessage = CONCAT('Update (ID=', @pnID, ') failed. Name already exists.');
而不是:

SET @errorMessage = 'Update (ID=' + @pnID + ') failed. Name already exists.';

我刚刚将大约300个存储过程添加到我的DBML中,并经历了这里和其他地方提到的许多问题

下面是错误原因和解决方案的摘要。根据我个人的经验,无法检测到以下存储过程的返回类型。请注意,以下所述的问题可能发生在发生错误的SP中,或者直接或间接从该SP调用的任何其他SP中

使用“+”符号将整数与字符串串联。对整数使用强制转换,或在SQL2012或更高版本中使用CONCAT语句。 引用其他数据库中的表。显然是权限问题。我没能解决这个问题。 对XP_CMDSHELL的任何直接或间接调用。我没能解决这个问题。 对其他存储过程的直接或间接调用中的任何语法错误。修复对SP的调用。 临时表格。用表变量替换临时表。 SET QUOTED_IDENTIFIER OFF正在使用中,但正在编辑的表上有索引视图*将set语句更改为将QUOTED_标识符设置为ON*
在参数声明之后添加这些行

AS
IF 1=0 BEGIN
 SET FMTONLY OFF
END

在此之后,编写BEGIN并开始您的过程工作。

与2012年SQL Server 2008R2相比,我也遇到了问题。在我的例子中,它是+运算符和代码中各种CAST语句的组合。我还没有找到用VisualStudio喜欢的东西替换它们的方法,但我想出了一个解决方法:

解决方案虚拟选择:

创建一个包含所有需要返回的字段的伪SELECT语句。例如: 注释掉SP代码,只需在SP中保留虚拟选择。 在O/R设计器中添加SP并将其保存,但不显示错误消息 恢复原始SP保留虚拟选择作为注释,以备将来使用
我找到的解决方案。。。如果条件不正确,我会在上面加一个SELECT,然后创建一个变量表,结果是他想退出,否则就把事情纠正过来。第一部分仅当您了解我想要的流程输出时。看看我的例子

ALTER PROCEDURE [dbo].[SS_getSearchedProductsDetailsNew]
(
 @mk int,
 @md int,
 @yr int = 0,
 @caroption int = 0,
 @condition int = 0,
 @producttype int = 0 ,
 @option int = 0, 
 @coloroption int = 0
)
AS

declare @sql nvarchar(max)

Begin
  if  @mk = 0 and @md = 0 and @yr = 0
    begin
        Declare @TempTable2 TABLE(
            ProductID numeric(10),
            TypeName nvarchar(50),
            MakeID numeric(10),
            ModelID numeric(10),
            ConditionID numeric(10),
            CarOptionsID numeric(10),
            OptionsID numeric(10),
            ColorOptionsID numeric(10),
            Make nvarchar(50),
            Model nvarchar(50),
            YearID numeric(5),
            Color  nvarchar(50),
            ProductType nvarchar(50),
            CarOptionName nvarchar(50),
            OptionName nvarchar(50),
            ColorOptionName nvarchar(50),
            ConditionName nvarchar(50),
            Notes  nvarchar(500),
            Price money,
            cog money)

            select * from @TempTable2

    end 

   else
   begin


  select @sql = '
    declare @theNotes  nvarchar(500)
    declare @theMake numeric(10), @theModel numeric(10), @theYear numeric(10)
    declare @makeName nvarchar(50), @modelName nvarchar(50), @ID numeric(5)
    declare @theProductType nvarchar(50), @theTypeName nvarchar(50)
    declare @theColor nvarchar(50),@theProductID numeric(10)
    declare @theCondition numeric(10),@theCarOption numeric(10) , @theOption numeric(10), @theColorOption numeric(10)
    declare @theConditionName nvarchar(50),@theCarOptionName nvarchar(50), @theOptionName nvarchar(50),@theColorOptionName nvarchar(50)
    declare @thePrice money, @theCog money


    declare @HoldingTable table(
        ID numeric identity,
        ProductID numeric(10),
        MakeID numeric(10),
        ModelID numeric(10),
        ConditionID numeric(10),
        CarOptionsID numeric(10),
        OptionsID numeric(10),
        ColorOptionsID numeric(10),
        Make nvarchar(50),
        Model nvarchar(50),
        YearID numeric(5),
        Color  nvarchar(50),
        ProductType nvarchar(50),
        Notes  nvarchar(500),
        Price money,
        cog money);

        INSERT INTO @HoldingTable (ProductID,MakeID, ModelID , ConditionID, CarOptionsID,OptionsID,ColorOptionsID, Make ,Model,YearID,Color,    ProductType, Notes, Price, cog) 
        SELECT   
            ProductNumber as ProductID,
            tblProductsForSale.MakeID as MakeID,
            tblProductsForSale.ModelID as ModelID ,
            ConditionID,
            CarOptionsID,
            OptionsID,
            ColorOptionsID,
            tblVehicleMake.Make as Make ,
            tblVehicleModel.Model as Model,
            YearID,
            Color,
            ProductType, Notes,
            tblProductsForSale.ResalePrice as Price,
            tblProductsForSale.SellPrice as cog
                from    tblProductsForSale, tblVehicleMake, tblVehicleModel where 
                tblProductsForSale.MakeID = tblVehicleMake.MakeID and  
                tblProductsForSale.ModelID = tblVehicleModel.ModelID 
                and tblProductsForSale.ProductStatus=''available'' and tblProductsForSale.Custom=0'

        if(@mk > 0)
        begin       
            select @sql = @sql + ' and tblProductsForSale.MakeID = ' + convert(varchar, @mk)
        end
        if @md > 0
        Begin
            select @sql = @sql + ' and tblProductsForSale.ModelID = ' + convert(varchar, @md)
        End
        if @yr > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.YearID = ' + convert(varchar, @yr)            
        end
        if @caroption > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.CarOptionsID = ' + convert(varchar, @caroption)
        end 
        if @producttype > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.ProductType = ''' + convert(varchar,@producttype)  + ''''
        end 
        if @option > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.OptionsID = ' + convert(varchar, @option)
        end 
        if @coloroption > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.ColorOptionsID = ' + convert(varchar, @coloroption)
        end     

        --select @sqlInsert = 'INSERT INTO @HoldingTable (ProductID,MakeID, ModelID , ConditionID, CarOptionsID,OptionsID,ColorOptionsID, Make ,Model,YearID,Color, ProductType, Price, cog) '
        --select @sqlExec = @sqlInsert + @sql


        --select * from @HoldingTable
        select @sql = @sql + 'Declare @TempTable2 TABLE(
            ProductID numeric(10),
            TypeName nvarchar(50),
            MakeID numeric(10),
            ModelID numeric(10),
            ConditionID numeric(10),
            CarOptionsID numeric(10),
            OptionsID numeric(10),
            ColorOptionsID numeric(10),
            Make nvarchar(50),
            Model nvarchar(50),
            YearID numeric(5),
            Color  nvarchar(50),
            ProductType nvarchar(50),
            CarOptionName nvarchar(50),
            OptionName nvarchar(50),
            ColorOptionName nvarchar(50),
            ConditionName nvarchar(50),
            Notes  nvarchar(500),
            Price money,
            cog money)

        WHILE Exists(Select * from @HoldingTable )
            begin
                Select @ID = ID FROM @HoldingTable 
                Select @theProductId = ProductID from @HoldingTable
                Select @theMake = MakeID  from @HoldingTable
                Select @theModel = ModelID  from @HoldingTable
                Select @theCondition = ConditionID  from @HoldingTable
                Select @theCarOption = CarOptionsID  from @HoldingTable
                Select @theOption = OptionsID  from @HoldingTable
                Select @theColorOption = ColorOptionsID  from @HoldingTable
                Select @theYear = YearID from @HoldingTable
                Select @theColor = Color from @HoldingTable
                Select @theProductType = ProductType from @HoldingTable
                Select @theTypeName = TypeName from tblProductType WHere ProductTypeID = cast (@theProductType as numeric(10))

                Select @thePrice = Price from @HoldingTable
                Select @theCog = cog from @HoldingTable

                Select @theConditionName = ConditionName from tblConditions Where ConditionID = @theCondition
                Select @makeName = Make from tblVehicleMake Where MakeID = @theMake
                Select @modelName = Model from tblVehicleModel Where ModelID = @theModel
                Select @theCarOptionName = CarOptionsName from tblCarOptions Where CarOptionsID = @theCarOption
                Select @theOptionName = OptionsName from tblOptions Where OptionsID = @theOption
                Select @theColorOptionName = ColorOptionsName from tblColorOptions Where ColorOptionsID = @theColorOption

                Select @theNotes = Notes from @HoldingTable
                Select @theProductType = ProductType from @HoldingTable

                INSERT INTO @TempTable2  (ProductID,TypeName,MakeID,ModelID,ConditionID ,CarOptionsID,OptionsID ,ColorOptionsID ,Make , Model , YearID ,Color,   ProductType, CarOptionName ,OptionName,ColorOptionName ,ConditionName, Notes, Price, cog)
                VALUES (@theProductId,@theTypeName, @theMake, @theModel, @theCondition, @theCarOption,@theOption,@theColorOption, @makeName,@modelName, @theYear, @theColor,@theProductType, @theCarOptionName, @theOptionName, @theColorOptionName, @theConditionName, @theNotes,  @thePrice , @theCog )
                DELETE FROM @HoldingTable  Where ID = @ID
            end

            Select * from @TempTable2 order by ProductID '


            end
            exec ( @sql )

    End

我在这方面做了很多努力,并得出结论,如果您的存储过程是动态的,并且与字符串组合在一起,那么您有时会错过一些东西。。因此,在导入Visual Studio DBML时,导入/更新无法执行/测试该过程
,因此返回类型保持未定义,一旦您更正了要执行的过程查询字符串,您就可以添加过程而不会出现任何问题。

在尝试将存储过程添加到DBML LINQ文件时遇到了此问题

通过一些研究,我发现当存储过程返回多个结果或使用临时表进行最终选择时,通常会发生这种情况

对我有效的解决方案是创建一个新的存储过程,将原始存储过程结果包装到一个表变量中,该表变量的列与temp表相同

我的包装器存储过程如下所示:

DECLARE @NewPrograms TABLE (
    Campaign_Number int,
    Campaign_Display nvarchar(255)
)

INSERT INTO @NewPrograms
    EXEC [dbo].[Original_Stored_Proc_With_Temp_Table_Result] @Program_ID


Select * 
From @NewPrograms
打开DBML文件,拖放新的包装器存储过程。

解决此问题的简单方法是2019年12月

1只需在tmp=>tmp之前设置双精度 2注释掉删除表tmp=>-删除表tmp 执行存储过程并确保显示数据 再次拖动存储过程,就这样,它将生成返回类型 最后,将您的店铺恢复到第一种情况,然后保存。
希望我能提供帮助。

我也有这个错误,最后我发现我已经更改了一个表字段名,在过程中它还没有更改,所以在添加到dbml时显示了一个错误。 现在,您可以在过程和表中检查字段是否相同


我希望这个经验是有用的。

我在拖放存储过程时遇到了相同的错误,所以我只是按照错误所说的操作:

未知返回类型 无法检测到以下存储过程的返回类型。在“属性”窗口中为每个存储过程设置返回类型

我选择了存储过程,然后选择了属性选项卡,有一个名为ReturnType的选项,该选项为空,然后点击该选项上的下拉按钮,然后选择创建SP并解决问题的表


如果这对你没有帮助,你可以试试上面的任何答案。

这篇博文可能有一天会消失。你能在你的答案中包括解决方案吗?当然,保留原来的归属。谢谢这篇博文基本上是这样写的:将诱惑转换为@TableVariables。我这样做了,这就解决了问题。感谢您提供的信息。将解决方案发布到此处-使用表变量替换临时表对我来说是一个有效的解决方案。感谢您提供的参考,节省我的时间:一个更清晰的答案只会说使用表变量代替存储过程中的任何临时表。这就是我的解决办法,这就是我的问题所在。我有一个存储过程正在访问另一个数据库中的表。我在设计时有访问权限,但我忘记了我的应用程序是作为一个没有访问权限的受限帐户运行的。出现此问题的sql登录没有数据库的所有者角色。将所有者角色分配给它时,问题就消失了。从此:-创建表tmptable[Start Time]DATE,[End Time]DATE;从@tmptable;中选择*对此:-----声明@tmptable表[开始时间]日期[结束时间]日期;从@tmptable中选择*-----除了这个,其他的解决方案都不适合我。我有一个相当复杂的SP,有多个with子句和生成的temp表。直到我将上述技术与包装器SP一起使用,才将临时表转换为表变量。谢谢!
ALTER PROCEDURE [dbo].[SS_getSearchedProductsDetailsNew]
(
 @mk int,
 @md int,
 @yr int = 0,
 @caroption int = 0,
 @condition int = 0,
 @producttype int = 0 ,
 @option int = 0, 
 @coloroption int = 0
)
AS

declare @sql nvarchar(max)

Begin
  if  @mk = 0 and @md = 0 and @yr = 0
    begin
        Declare @TempTable2 TABLE(
            ProductID numeric(10),
            TypeName nvarchar(50),
            MakeID numeric(10),
            ModelID numeric(10),
            ConditionID numeric(10),
            CarOptionsID numeric(10),
            OptionsID numeric(10),
            ColorOptionsID numeric(10),
            Make nvarchar(50),
            Model nvarchar(50),
            YearID numeric(5),
            Color  nvarchar(50),
            ProductType nvarchar(50),
            CarOptionName nvarchar(50),
            OptionName nvarchar(50),
            ColorOptionName nvarchar(50),
            ConditionName nvarchar(50),
            Notes  nvarchar(500),
            Price money,
            cog money)

            select * from @TempTable2

    end 

   else
   begin


  select @sql = '
    declare @theNotes  nvarchar(500)
    declare @theMake numeric(10), @theModel numeric(10), @theYear numeric(10)
    declare @makeName nvarchar(50), @modelName nvarchar(50), @ID numeric(5)
    declare @theProductType nvarchar(50), @theTypeName nvarchar(50)
    declare @theColor nvarchar(50),@theProductID numeric(10)
    declare @theCondition numeric(10),@theCarOption numeric(10) , @theOption numeric(10), @theColorOption numeric(10)
    declare @theConditionName nvarchar(50),@theCarOptionName nvarchar(50), @theOptionName nvarchar(50),@theColorOptionName nvarchar(50)
    declare @thePrice money, @theCog money


    declare @HoldingTable table(
        ID numeric identity,
        ProductID numeric(10),
        MakeID numeric(10),
        ModelID numeric(10),
        ConditionID numeric(10),
        CarOptionsID numeric(10),
        OptionsID numeric(10),
        ColorOptionsID numeric(10),
        Make nvarchar(50),
        Model nvarchar(50),
        YearID numeric(5),
        Color  nvarchar(50),
        ProductType nvarchar(50),
        Notes  nvarchar(500),
        Price money,
        cog money);

        INSERT INTO @HoldingTable (ProductID,MakeID, ModelID , ConditionID, CarOptionsID,OptionsID,ColorOptionsID, Make ,Model,YearID,Color,    ProductType, Notes, Price, cog) 
        SELECT   
            ProductNumber as ProductID,
            tblProductsForSale.MakeID as MakeID,
            tblProductsForSale.ModelID as ModelID ,
            ConditionID,
            CarOptionsID,
            OptionsID,
            ColorOptionsID,
            tblVehicleMake.Make as Make ,
            tblVehicleModel.Model as Model,
            YearID,
            Color,
            ProductType, Notes,
            tblProductsForSale.ResalePrice as Price,
            tblProductsForSale.SellPrice as cog
                from    tblProductsForSale, tblVehicleMake, tblVehicleModel where 
                tblProductsForSale.MakeID = tblVehicleMake.MakeID and  
                tblProductsForSale.ModelID = tblVehicleModel.ModelID 
                and tblProductsForSale.ProductStatus=''available'' and tblProductsForSale.Custom=0'

        if(@mk > 0)
        begin       
            select @sql = @sql + ' and tblProductsForSale.MakeID = ' + convert(varchar, @mk)
        end
        if @md > 0
        Begin
            select @sql = @sql + ' and tblProductsForSale.ModelID = ' + convert(varchar, @md)
        End
        if @yr > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.YearID = ' + convert(varchar, @yr)            
        end
        if @caroption > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.CarOptionsID = ' + convert(varchar, @caroption)
        end 
        if @producttype > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.ProductType = ''' + convert(varchar,@producttype)  + ''''
        end 
        if @option > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.OptionsID = ' + convert(varchar, @option)
        end 
        if @coloroption > 0
        begin
            select @sql = @sql + ' and tblProductsForSale.ColorOptionsID = ' + convert(varchar, @coloroption)
        end     

        --select @sqlInsert = 'INSERT INTO @HoldingTable (ProductID,MakeID, ModelID , ConditionID, CarOptionsID,OptionsID,ColorOptionsID, Make ,Model,YearID,Color, ProductType, Price, cog) '
        --select @sqlExec = @sqlInsert + @sql


        --select * from @HoldingTable
        select @sql = @sql + 'Declare @TempTable2 TABLE(
            ProductID numeric(10),
            TypeName nvarchar(50),
            MakeID numeric(10),
            ModelID numeric(10),
            ConditionID numeric(10),
            CarOptionsID numeric(10),
            OptionsID numeric(10),
            ColorOptionsID numeric(10),
            Make nvarchar(50),
            Model nvarchar(50),
            YearID numeric(5),
            Color  nvarchar(50),
            ProductType nvarchar(50),
            CarOptionName nvarchar(50),
            OptionName nvarchar(50),
            ColorOptionName nvarchar(50),
            ConditionName nvarchar(50),
            Notes  nvarchar(500),
            Price money,
            cog money)

        WHILE Exists(Select * from @HoldingTable )
            begin
                Select @ID = ID FROM @HoldingTable 
                Select @theProductId = ProductID from @HoldingTable
                Select @theMake = MakeID  from @HoldingTable
                Select @theModel = ModelID  from @HoldingTable
                Select @theCondition = ConditionID  from @HoldingTable
                Select @theCarOption = CarOptionsID  from @HoldingTable
                Select @theOption = OptionsID  from @HoldingTable
                Select @theColorOption = ColorOptionsID  from @HoldingTable
                Select @theYear = YearID from @HoldingTable
                Select @theColor = Color from @HoldingTable
                Select @theProductType = ProductType from @HoldingTable
                Select @theTypeName = TypeName from tblProductType WHere ProductTypeID = cast (@theProductType as numeric(10))

                Select @thePrice = Price from @HoldingTable
                Select @theCog = cog from @HoldingTable

                Select @theConditionName = ConditionName from tblConditions Where ConditionID = @theCondition
                Select @makeName = Make from tblVehicleMake Where MakeID = @theMake
                Select @modelName = Model from tblVehicleModel Where ModelID = @theModel
                Select @theCarOptionName = CarOptionsName from tblCarOptions Where CarOptionsID = @theCarOption
                Select @theOptionName = OptionsName from tblOptions Where OptionsID = @theOption
                Select @theColorOptionName = ColorOptionsName from tblColorOptions Where ColorOptionsID = @theColorOption

                Select @theNotes = Notes from @HoldingTable
                Select @theProductType = ProductType from @HoldingTable

                INSERT INTO @TempTable2  (ProductID,TypeName,MakeID,ModelID,ConditionID ,CarOptionsID,OptionsID ,ColorOptionsID ,Make , Model , YearID ,Color,   ProductType, CarOptionName ,OptionName,ColorOptionName ,ConditionName, Notes, Price, cog)
                VALUES (@theProductId,@theTypeName, @theMake, @theModel, @theCondition, @theCarOption,@theOption,@theColorOption, @makeName,@modelName, @theYear, @theColor,@theProductType, @theCarOptionName, @theOptionName, @theColorOptionName, @theConditionName, @theNotes,  @thePrice , @theCog )
                DELETE FROM @HoldingTable  Where ID = @ID
            end

            Select * from @TempTable2 order by ProductID '


            end
            exec ( @sql )

    End
DECLARE @NewPrograms TABLE (
    Campaign_Number int,
    Campaign_Display nvarchar(255)
)

INSERT INTO @NewPrograms
    EXEC [dbo].[Original_Stored_Proc_With_Temp_Table_Result] @Program_ID


Select * 
From @NewPrograms