我有一个存储过程,它有2个输入参数并返回多个 结果设置。
ALTER PROCEDURE [dbo].[sp_GetList]
@eid int,
@sid int,
AS
SELECT ID, NAME FROM EMPLOYEE WHERE id=@eid;
SELECT ID, NAME FROM STUDENTS WHERE id=@sid
在实体框架中,我将此存储过程称为如下。
我正在使用msdn。
中的这个教程https://msdn.microsoft.com/en-us/library/jj691402(v=vs.113).aspx
using (var db = new APIContext()) {
db.Database.Initialize(force: false);
var cmd = db.Database.Connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "[dbo].[sp_GetList]";
DbParameter eid = cmd.CreateParameter();
eid.ParameterName = "@eid";
eid.DbType = System.Data.DbType.Int32;
eid.Direction = ParameterDirection.Input;
eid.Value = resourceID;
DbParameter sid = cmd.CreateParameter();
sid.ParameterName = "@sid";
sid.DbType = System.Data.DbType.Date;
sid.Direction = ParameterDirection.Input;
sid.Value = sid;
cmd.Parameters.Add(sid);
try
{
db.Database.Connection.Open();
var reader = cmd.ExecuteReader();
EmpList = ((IObjectContextAdapter)db)
.ObjectContext
.Translate<Shared.Model.EmpList>(reader).ToList();
MList.EmpList = EmpList;
reader.NextResult();
SList = ((IObjectContextAdapter)db)
.ObjectContext
.Translate<Shared.Model.SList>(reader).ToList();
MList.SList = SList;
}
finally
{
db.Database.Connection.Close();
}
当我运行此代码时,我收到错误:
Additional information: Procedure or function 'sp_GetList' expects parameter '@eid', which was not supplied.
我理解这对于ado.net来说是非常基本的错误,但使用Entity框架会有所不同。
任何帮助都是相关的。
答案 0 :(得分:3)
您的代码似乎丢失了:
cmd.Parameters.Add(eid);