我试图在单行的列上执行简单的UPDATE
。我收到Sequence contains no elements
例外。
private void InsertUpdateFileLocation(string targetFileLocationAndFullName,
tbFileAttachment linkGuid)
{
ISESEntities context = new ISESEntities();
var query = (from f in context.tbFileAttachments
where f.CCCPGUID == linkGuid.CCCPGUID
select f).First();
query.FileLocation = targetFileLocationAndFullName;
context.SaveChanges();
}
答案 0 :(得分:4)
在这种情况下,您没有与您要搜索的值匹配的记录。您可以使用FirstOrDefault
然后测试null:
var query = (from f in context.tbFileAttachments
where f.CCCPGUID == linkGuid.CCCPGUID
select f).FirstOrDefault();
if(query==null)
{
//no match found!
}