在 Entity Framework Core 中使用 `ExecuteSqlRaw` 执行存储过程后显示错误

After executing stored procedure with `ExecuteSqlRaw` in Entity Framework Core showing error

我得到的错误是:

The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects.

在我 运行 这个代码之后:

var sqlparamPayRunId = new SqlParameter("@PayRunId", payRunId);
sqlparamPayRunId.SqlDbType = SqlDbType.BigInt;
CRMDbContext.Database.ExecuteSqlRaw("EXEC DeletePayRun @PayRunId", sqlparamPayRunId);

我在使用 EFCore5 时遇到了这个错误,我将 sqlParameter 命名空间从 System.Data.SqlClient 更改为 Microsoft.Data.SqlClient .