我有以下更新方法,似乎有效:
public Folder UpdateFolder(Folder folder)
{
Folder serverFolder = _db.Folders.FirstOrDefault(f => f.FolderId == folder.FolderId);
if (serverFolder != null)
{
serverFolder.Title = folder.Title;
serverFolder.Details = folder.Details;
}
SaveChanges();
return serverFolder;
}
我刚刚注意到,我读过的大多数更新方法都调用了 Entry.StateDetached 和 StateAttached - 我在上面所做的一切正常,还是我遗漏了什么?