我有一个通过 DBContext 调用的存储过程,如下所示:
using (var transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0)))
{
using (var db = new IceCreamEntities(connectionString, null, null))
{
db.CallMyProc(dateTime);
var num = db.SaveChanges();
}
transScope.Complete();
}
编辑:该过程根据传入的日期时间值和数据库中已知的一些其他信息删除一些行。
proc 确实有效 - 我的集成测试在执行 proc 后验证表的行数是否正确 - 但我总是返回 0 作为受影响的行数。
想法?
我正在运行:EF 4.3、MySQL 5.5.28、MySQL 连接器 6.5.4
已解决:请参阅下面的答案。
最佳答案
已解决:
好吧,答案是忽略 db.SaveChanges() 的返回,而是使用调用过程本身返回的值。所以,现在看起来是这样:
using (var transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0)))
{
using (var db = new IceCreamEntities(connectionString, null, null))
{
var num = db.CallMyProc(dateTime); //<<<<<< set it here instead
db.SaveChanges();
}
transScope.Complete();
}
我的测试中有一个错误,它使 db.CallMyProc 调用也返回 0,因此这掩盖了调用确实返回了受影响的行数这一事实。
仍然不确定为什么 SaveChanges 没有,但无论如何。
关于mysql - Entity Framework 和 MySQL - 不返回受影响的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14216699/