EF Core can create instances of new classes using projections. In this section, Phil discusses the ramifications of using projections and then demonstrates creating anonymous objects as well as instances of a ViewModel.
- [Instructor] EFCore also supports LINQ projections,…which enables you to create new objects…from the entities that you queried.…They can be anonymous or strongly typed.…Projections do not participate in change tracking.…Creating new object is not part of DBSet…and therefore if you make changes to it…Entity Framework will not know how to persist it.…If you're using a view model,…which is a common use for projections,…then you will need to convert back into…standard Entity classes…that Entity Framework can understand.…
Now let's go see some projections in action.…Open up the ProjectionTest class…and let's start with ShouldCreateNewAnonymousObjects.…So let's create a variable to hold them…and this will be called the newObjectList.…And we have to use var because these are dynamic.…So Product.Where and once again we'll select…where the MakeFlag is true.…
And then we're going to select,…and this will create a new object for us.…Let's add an OrderBy,…'cause I want to discuss that a little bit.…And we can't put the lambda in their yet.…
- Entity Framework Core components and projects
- Working with scaffolded files
- Testing with xUnit
- Viewing generated SQL
- Composing queries
- Sorting and filtering results
- Working with aggregates
- Loading related data
- Logging and tracking
- Mapping functions
- Generics and delegates
- Checking concurrency
- Resiliency and transactions
Skill Level Intermediate
Learning Entity Framework Corewith Reynald Adolphe1h 35m Intermediate
1. Get to Know Entity Framework
2. Set the Stage
3. Querying Data: Part 1
4. Querying Data: Part 2
5. Advanced Query Features
6. Persisting Data
7. DbContext Options and Configuration
Thank you1m 23s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.