linq到sql存储过程调用失败

时间:2011-01-26 11:39:11

标签: linq-to-sql

我在SQL Server上有递归存储过程。我正在使用Linq-to-SQL生成的类,并且拖放&把程序放到这个班上。

其他程序运行正常,但此程序失败,例外情况如下:

  

“System.Void”不允许返回   类型。无效的操作异常

存储过程:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[delListEnterprise]
@pin_list_enterprise_id numeric(38,0), 
@cCriteria varchar(250) = null,
@iLevel int = 0
AS
begin
set nocount on
declare
    @cSQL varchar(255),
    @cChildCriteria varchar(255),
    @iLevelNew int
IF @iLevel = 0
    BEGIN
        set @cCriteria='parent_list_enterprise_id='+cast(@pin_list_enterprise_id as varchar(30));
        delete from list_enterprise where list_enterprise_id=@pin_list_enterprise_id;
        Create Table #tblCascadeDelete (CallLevel int NOT NULL, PKValue int NOT NULL)
    END
SET @cSQL = 'INSERT INTO #tblCascadeDelete ( CallLevel, PKValue ) SELECT ' + Convert(varchar(3), @iLevel) + ' As CallLevel, list_enterprise_id As PKValue FROM list_enterprise WHERE ' + @cCriteria
EXEC (@cSQL)
IF @@RowCount > 0
    BEGIN
        SET @cChildCriteria = '[parent_list_enterprise_id] IN (SELECT [PKValue] FROM #tblCascadeDelete Where [CallLevel] = ' + Convert(varchar(3), @iLevel) + ')'
        SET @iLevelNew = @iLevel + 1
        EXEC delListEnterprise null,@cChildCriteria, @iLevelNew
    END
SET @cSQL = 'DELETE FROM list_enterprise WHERE ' + @cCriteria
EXEC (@cSQL)
IF @iLevel = 0
    BEGIN
        Drop Table #tblCascadeDelete
    END
ELSE
    DELETE FROM #tblCascadeDelete WHERE CallLevel = @iLevel
end

如果我在SQL Server Management Studio中运行它,它可以工作。

1 个答案:

答案 0 :(得分:0)

只需将一个返回/输出参数添加到存储过程即可。我怀疑这是一个Linq2SQL限制(或没有人想到它)。