开发者

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开发者_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();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜