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开发者_Go百科 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.
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).
Call SaveChanges() on the DbContext
Entity Framework: SaveChanges();
Linq-to-SQL: SubmitChanges();
精彩评论