我想更新实体对象记录,但它不显示异常但它不更新记录。实体框架Linq更新数据不起作用
在objetct以前它包含空值issue_detail,之后用户更新数据调用下面的方法
public Boolean bookReturnedUpdate(Issue_Detail issue)
{
BookController bookController = new BookController();
int bookID = (int) issue.book_id;
Book_Detail book = bookController.findByBookID(bookID);
int noOfCopies = (int) book.no_of_copies;
book.no_of_copies = ++noOfCopies;
Console.Write("just before the update");
bookController.updateBook(book);
Console.WriteLine("Issue ID" +issue.issue_id);
Boolean status = false;
try
{
using (var db = new ModelDB())
{
DateTime issueD = (DateTime) issue.return_date;
Console.WriteLine("Details " + issueD); // here I can see the date is update and it contains the new date I have inserted
db.Entry(issue).State = EntityState.Modified;
db.Issue_Detail.Attach(issue);
db.SaveChanges(); // this returns 0 when I have checked wit h Console.WriteLine
status = true;
}
}
catch (Exception ex)
{
Console.WriteLine("Book return update error " + ex.InnerException);
}
return status;
}
谢谢。
我已经尝试过db.SaveChanges()也没有人若需要完整的资料库,请检查下面的链接Github上 https://github.com/ccmcwolf/LibraryManagementSystem
你为什么要叫'db.Issue_Detail.Attach(发行);以后'db.Entry(问题).STATE = EntityState.Modified';'? – grek40
我试着只是添加db.SaceChanges()它没有工作,这就是为什么试图添加也是 –