Francesco
Francesco

Reputation: 964

How do I update objects using a DbContext?

How do I use the class DbContext to update a collection of objects?

I have a DbContext Class called "Animals". Animals has a DbSet called "Reptiles" which is another class. I can query the Animals with Linq to get the objects I want from the Reptiles. Now, how do I update those objects which I got from the query? I want to save back into the database the changes I do.

Upvotes: 2

Views: 2276

Answers (3)

Ken D
Ken D

Reputation: 5968

Entity Framework: SaveChanges();
Linq-to-SQL: SubmitChanges();

Upvotes: 1

Richard
Richard

Reputation: 1800

Call SaveChanges() on the DbContext

Upvotes: 2

Brian Ball
Brian Ball

Reputation: 12606

The context should have a method that does this for you, I believe it's called SaveChanges(). With EF (like most ORMs) there isn't a way of saving a single entity (not easily at least).

Upvotes: 2

Related Questions