我有一个带参数的存储过程,我想从EF 6.1.3的CodeFirst实现中运行它。此特定sp从表中删除行,除了删除的行数外不返回任何内容。我不太清楚该怎么做。假设存储过程是sp_DeleteTheseRows,它只需要一个参数@TheParam。那怎么样?我想它会使用ExecuteSQLCommand。它会是:
MyContext.Database.ExecuteSQLCommand(“exec dbo.sp_DeleteTheseRows @TheParam”,新的SqlParameter(“@ TheParam”,userSuppliedParam));
答案 0 :(得分:0)
确保已将命令类型定义为storedprocedure, cmd.CommandType = StoredProcedure;
答案 1 :(得分:0)
这是我发现的。以下所有内容都是上述问题的解决方案:
DbContext.Database.ExecuteSqlCommand(“exec dbo.sp_DeleteTheseRows @ p0”,MyValue);
原来你真的不需要EXEC
DbContext.Database.ExecuteSqlCommand(“dbo.sp_DeleteTheseRows @ p0”,MyValue);
DbContext.Database.ExecuteSqlCommand(“dbo.sp_DeleteTheseRows @Code”,新的SqlParameter(“@ Code”,MyValue));