开发者

How do I update objects using a DbContext?

开发者 https://www.devze.com 2023-02-18 08:14 出处:网络
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 que

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

精彩评论

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

关注公众号