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 - .NET Tutorial
From the course: .NET Essentials: LINQ for Databases
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
-
-
-
-
-
Explore the relevant LINQ types4m 24s
-
(Locked)
Understand the DbContext2m 38s
-
(Locked)
Queryable types: DbSet and DbQuery1m 30s
-
(Locked)
DbSet, the basis for EF collection models1m 57s
-
(Locked)
Save changes in DbSet3m 1s
-
(Locked)
DbQuery, the basis of LINQ queries for EF models1m 4s
-
(Locked)
Interfaces: IEnumerable and IQueryable1m 41s
-
(Locked)
View the Expression Tree1m 20s
-
(Locked)
View the generated SQL1m 25s
-
-
-
-