.NET Essentials: LINQ for Databases
1h 15mIntermediate2021-01-15
Authors

Walt Ritscher
Programmer, UI Designer, Staff Instructor at LinkedIn Learning
Course details
The first explanation you typically hear about Microsoft LINQ is that it provides an in-language query tool to manipulate the contents of arrays and lists. Explore LINQ further and you’ll find it works with other popular data sources like databases and XML files. That makes it a universal query tool that simplifies working with any data source. In this course, part of a three-course series, LinkedIn Learning staff author Walt Ritscher uses LINQPad, a lightweight, powerful code editor, to illustrate useful topics like queryable types, basic query syntax, finding data by date range, and how to use LINQ queries to reduce database network traffic. After completing this course, you’ll have a solid foundation on using LINQ to query database and Entity Framework data.
Skills covered
.NETDatabase DevelopmentDatabase ManagementSoftware Development ToolsMicrosoftSoftware DevelopmentOne-Off
Concepts
Introduction
- Query your database data with LINQ
- What you should know
- How to access the sample code on GitHub
- Why this course uses LINQPad
- Install LINQPad
Get Started
- Understand LINQ for Databases
- Examine the Entity Framework sample
- Use the EF models in an application
- Quick look at how to create EF models
Databases and LINQPad
- Connect to included sample database
- Connect to another database
- Connect to EF model in a .NET assembly
- View the database structures in LINQPad
Explore Queryable Types
- Explore the relevant LINQ types
- Understand the DbContext
- Queryable types - DbSet and DbQuery
- DbSet, the basis for EF collection models
- Save changes in DbSet
- DbQuery, the basis of LINQ queries for EF models
- Interfaces - IEnumerable and IQueryable
- View the Expression Tree
- View the generated SQL
Basic Query Syntax
- Basic concepts of LINQ
- Enumerable and Queryable extension methods
- Use extension methods syntax
- Use query expression syntax
Fun with Queries
- Projection, get fewer columns
- Paging with Take and Skip
- Use Find for faster search by key
- Use EF navigation properties instead of joins
- Use the Contains method for
- Organize query results into groups with GroupBy
- Flatten child collections with SelectMany
- Find data within a date range
Conclusion
- Next steps