【发布时间】:2015-08-27 11:52:57
【问题描述】:
此代码因错误而失败:“必须声明标量值@prodID”。有什么建议吗?
using (var ctx = new StewieDataModel())
{
string productID = "81";
var techData = ctx.Database.SqlQuery<TechData>("dbo.usp_DS_GetTechData @prodID", productID).ToList();
}
这是模型:
namespace DatasheetData
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
public partial class StewieDataModel : DbContext
{
public StewieDataModel()
: base("name=StewieConnectionString")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
}
}
这是我要填充的类:
namespace DatasheetData
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("usp_DS_GetTechData")]
public partial class TechData
{
public string TestCategory { get; set; }
public string TestName { get; set; }
public string TestResultLabel { get; set; }
public string TestResult { get; set; }
public string TestMethod { get; set; }
}
}
这是我在 SSMS 中成功调用它的方法:
DECLARE @return_value int
EXEC @return_value = [dbo].[usp_DS_GetTechData]
@prodID = "81"
SELECT 'Return Value' = @return_value
GO
【问题讨论】:
标签: c# sql-server entity-framework ef-code-first