3
我試圖調用存儲過程使用C#EF6帶回數據。我試圖在SQL管理工作室中運行存儲過程,但它似乎工作正常,但是當我嘗試在我的應用程序中運行它時,出現錯誤,說"Must declare the scalar variable "@devID"
EF6存儲過程必須聲明標量變量
這是我的應用程序的一部分,存儲過程
public IHttpActionResult GetMetrics(int deviceID, string attribute, string startDate)
{
if (deviceID == 0)
{
return NotFound();
}
var metrics = db.Database.SqlQuery<Metrics>("GetMetrics @devID, @MetricType, @startTime", deviceID, attribute, startDate).ToList();
,這裏是我的存儲過程:
ALTER PROCEDURE [dbo].[GetMetrics]
-- Add the parameters for the stored procedure here
@devID int,
@MetricType nvarchar(20),
@startTime nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT *
FROM dbMetrics
WHERE deviceID = @devID and MetricType = @MetricType and timeStamp >= @startTime
ORDER BY timeStamp
END