[英]Entity Framework not updating record in the method
我在我的ASP.NET MVC网站上使用了EF,但我注意到一个新的actionresult()
方法中存在一个“问题”。
在同一动作中,我在同一测试表中有两个操作。
码:
//Break point 01
_documentRepository.UpdateStatus(documentToUpload.IDDocument, Status.Admin);
//Break point 02 - Just create this aux var to break here and check the database.
var aux = 1;
//Break point 03
var documents = documentRepository.GetByID(documentToUpload.IDProtocol).ToList();
foreach(var doc in documents)
{
if(doc.Status == Status.Admin)
{
//Break point 04
//Never Breaks here.
}
}
当断点02触发时,我进入数据库并检查Document的状态,它已经等于Status.Admin (正如我在断点01代码中所做的更改)。 但是,当我获得文档列表时,我会签入该列表,并且文档仍处于较旧的状态。
可能是什么?
编辑:
仓库代码:
public IEnumerable<Document> GetByID(Guid idProtocol)
{
return _context.Document.Where(d => d.IDProtocol.Equals(idProtocol));
}
我找到了解决方案,这是我做错的。 我正在使用同一个存储库对象来执行这两项操作。 我在Action方法内创建了一个新的DocumentRepository对象,并使用它来获取文档列表,然后得到列表更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.