我为我的程序使用CodeFirst和存储库模式。我用作上下文的数据库有一个我在SQL Server Management Studio中创建和测试的存储过程,名为dbo.sp_InsertTrackingInfo
。CodeFirst调用存储过程
在我的基地仓库类我有
public IEnumerable<T> ExecWithStoreProcedure(string query, int id)
{
return _context.Database.SqlQuery<T>("sp_InsertTrackingInfo @estimate", new SqlParameter("estimate", id));
}
在管理工作室的作品,其中估计被定义为一个整数
EXEC sp_InsertTrackingInfo @estimate = '14'
所有操作与此例外取得工作中使用此查询所以我知道我指向了正确的位置,我已经检查过SQL Server Profiler,并且在调用此函数的任何时候都不会调用此过程。
任何人都有这方面的经验?
感谢, Bmckie
编辑:
在仓库的一个
using (var uow = UnitOfWorkManager.Begin())
{
uow.EstimateTrackingRepository.Insert(t);
uow.EstimateTrackingRepository.ExecWithStoreProcedure("exec sp_InsertTrackingInfo @estimate", t.EstimateId);
uow.Commit();
}
哪个代码调用'ExecWithStoreProcedure'? – 2014-10-01 21:08:42
我将它添加到编辑 – 2014-10-01 21:10:03
我认为你需要在'SqlQuery'之后或者在调用'ExecWithStoreProcedure'后执行类似'ToArray()'的查询,程序是否在插入语句之后选择查询?如果它只是一个插入语句,可能你可以使用'ExecuteSqlCommand'。 – 2014-10-01 21:16:22