How to Get results from multiple tables using LINQ
How to Get results from multiple tables using LINQ
25405-Sep-2023
Updated on 06-Sep-2023
Home / DeveloperSection / Forums / How to Get results from multiple tables using LINQ
How to Get results from multiple tables using LINQ
Aryan Kumar
06-Sep-2023To retrieve results from multiple tables using LINQ, you can use the
Join
operator. TheJoin
operator takes two or more tables as input and returns a new table that contains the rows from all the tables that match the join condition.The join operator has the following syntax:
where
source
is the name of the first table,otherSource
is the name of his second table,column1
is the name of the column in the first table that is used to join the tables, andcolumn2
is the name of the columns of the second table that is used to join the tables.For example, the following code joins the
Customers
andOrders
tables:This code returns a new table that containing the names of all the customers and the IDs of all orders.
You can also join three or more tables using the
Join
operator. For example, the following code joins theCustomers
,Orders
, andProducts
tables:This code returns a new table containing the name of all customers, the IDs of all orders, and the names of all the products that they ordered.