From the course: .NET Essentials: LINQ for Databases

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Save changes in DbSet

Save changes in DbSet - .NET Tutorial

From the course: .NET Essentials: LINQ for Databases

Start my 1-month free trial

Save changes in DbSet

- [Instructor] Earlier in this course, we looked at the differences between DbSet and DbQuery. The major difference is that DbSet supports methods for modifying the contents of the DbSet. We're going to look at the add and remove method, and I'll do that in these two tabs DbSet Add and DbSet Remove. What am I doing over here when I add the item? I'm working with the regions table. So I will instantiate a new region here in line eight, has a primary ID or region ID of 44 and the description Northwest. Then on line 11, I call dot add to put it in the DbSet. I'm also showing you what's the state of the table before and after I do that action. How I run this query and I see there are four items before and four items after. Reason the data hasn't persisted is I haven't saved the changes to the database. To do that, I work with the DBcontext. So I'll call context dot save changes, like this. Now execute the query again.…

Contents