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.

Comments (2)

John Frank

2/22/2024 5:16:22 AM
This message got to you and I can help you get your ad message to millions of websites just like this. It's a bargain compared to regular advertising.Contact me by email below if you want to know more. Regards, Phil Stewart philstewart@myyahoo.com

Gia Pham

2/19/2024 11:35:29 AM
Hello! We run an Instagram growth service, which increases your number of followers both safety - Guaranteed: We guarantee to gain you 400-1200+ followers per month - Real human followers: People follow you because they are interested in your business or niche - Safe: All actions are made manually. We do not use any bots. The price is just $60 (USD) per month, and we can start immediately. If you are interested and would like to see some of our previous work, let me know and we can discuss further. Kind Regards, GIA. To Unsubscribe, reply with the word unsubscribe in the subject.

Leave a Comment

All fields are required. Your email address will not be published.