Entity Framework Core Data Providers convert LINQ statements into datastore specific code when they are executed. In this section, Phil shows how to view the generated SQL using an extension method provided by the EF Community.
- [Narrator] When debugging an application,…it's often helpful to be able to view…the SQL generated from the LINQ statements.…An EF6 is very easy,…you can simply call to string on a query.…This mechanism does not exist in EF Core.…So there are three main options…for viewing a generated SQL.…You can use a database profiler,…as we did in the last section.…You can use logging.…EF, of course, supports the ILogger factory pattern…throughout .NET core.…
Or you could build custom extension methods…to extract that information from the IQueryable.…Heres where I tip my hat to Ricardo Peres…and the EF community,…for solving the problem of viewing simple generated SQL.…On the screen is a link to Ricardo's blog…where he talks about it…and also the GitHub issue in Entity Framework core…that talks even more about the issue.…The extension method is included…in the Iqueryable extensions for generated SQL class…that you included in your project…from the downloadable code.…
And it provides a ToSql method…as an extension method of off an Iqueryable.…
- 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.