Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带EF Core的存储过程输出-SqlParameterCollection只接受非空的SqlParameter类型对象,而不接受SqlParameter对象_C# - Fatal编程技术网

C# 带EF Core的存储过程输出-SqlParameterCollection只接受非空的SqlParameter类型对象,而不接受SqlParameter对象

C# 带EF Core的存储过程输出-SqlParameterCollection只接受非空的SqlParameter类型对象,而不接受SqlParameter对象,c#,C#,我有一个C#代码,它调用SQL Server存储过程,但收到错误消息SqlParameterCollection只接受非空的SqlParameter类型对象,而不接受SqlParameter对象。 var output = new SqlParameter(); output.ParameterName = "@id"; output.SqlDbType = SqlDbType.Int; output.Direc

我有一个C#代码,它调用SQL Server存储过程,但收到错误消息
SqlParameterCollection只接受非空的SqlParameter类型对象,而不接受SqlParameter对象。

        var output = new SqlParameter();
        output.ParameterName = "@id";
        output.SqlDbType = SqlDbType.Int;
        output.Direction = ParameterDirection.Output;

        var sproc_cmd = "dbo.AddFileFolderStructure";
       
        try
        {
            var sproc_response = await Database.ExecuteSqlInterpolatedAsync($"{sproc_cmd} {id}, {folderName}, {folderType}, {output} OUT");

        }
        catch (Exception ex)
        {

            throw;
        }
这是我的存储过程

ALTER PROCEDURE [dbo].[AddFileFolderStructure]
(@ParentId INT, @FolderName VARCHAR(255), @FolderType VARCHAR(255),@id int output)
AS
BEGIN
    -- Get the root node we wish to insert a descendant of
    DECLARE @ReportsToNode HIERARCHYID
    SELECT @ReportsToNode = [Node] FROM [FileFolders]
    WHERE Id = @ParentId

    -- Determine the last child position
    DECLARE @LastChildPosition HIERARCHYID
    SELECT @LastChildPosition = MAX([Node]) FROM [FileFolders]
    WHERE [Node].GetAncestor(1) = @ReportsToNode

    INSERT INTO [FileFolders] 
    VALUES (@ReportsToNode.GetDescendant(@LastChildPosition, null), @FolderName, @FolderType)

    SELECT @id = SCOPE_IDENTITY();
    return @id
END

没有输出,它运行正常。但是我需要输出来获得插入的标识。

我已经解决了它。谢谢<代码>等待数据库.ExecuteSqlInterpolatedAsync($“{sproc_cmd}{id},{folderName},{folderType},{output}OUT”)