Successfully added
EF Core
by Patrik
Disconnected Scenario
Make EF Core update only the updated properties by turning the disconnected scenario to connected.
public void SaveBook(Book book)
{
// Here, 'book' is the book with the changed Title.
using(var context = new TestContext())
{
var dbBook = context.Books.Find(book.ID);
// Copy book's property values to dbBook.
context.Entry(dbBook).CurrentValues.SetValues(book);
context.SaveChanges();
}
}
There may be good reasons to prefer the latter method above the former.
Referenced in:
Comments(2)
John Frank
2/22/2024 5:16:22 AMGia Pham
2/19/2024 11:35:29 AM