How to get multiple tables using Entity Framework Core
How to get multiple tables using Entity Framework Core
22705-Sep-2023
Updated on 06-Sep-2023
Home / DeveloperSection / Forums / How to get multiple tables using Entity Framework Core
How to get multiple tables using Entity Framework Core
Aryan Kumar
06-Sep-2023To get multiple tables using Entity Framework Core, you can use the
DbSet
class. The classDbSet
represents a collection of entities from a single table. You can load related entities from another table into the current entity using the include method.For example, the following code gets all the customers and their orders in one LINQ call:
C#
This code will first loads all the customers from the
Customers
table. Then, load all the orders for each customer from theOrders
table.You can also use the
Include
method to load multiple related entities in one LINQ call. For example, the following code gets all the customers, their orders, and the products that they ordered in one LINQ call:C#
This code will first loads all the customers from the
Customers
table. Then, load all the orders for each customer from theOrders
table. Finally, all products ordered by each customer are loaded from theProducts
table.Here are some other things to keep in mind when getting multiple tables using Entity Framework Core:
Where
operator to filter the query results.OrderBy
operator to sort the result of your query.Take
andSkip
operators to paginate the query results.