Here's an example of how to perform a join using LINQ query syntax in C#:
Suppose we have two collections of objects: orders
and customers
. Each order
object has a CustomerId
property, which is the same as the Id
property of a corresponding customer
object.
main.cs324 chars9 lines
In the above example, we perform a join on the CustomerId
and Id
properties of the Order
and Customer
objects, respectively. We then select a new anonymous object with properties OrderId
and CustomerName
.
Note that join
is a keyword in LINQ query syntax that performs an inner join. There are also other types of joins available, such as left join
, right join
, and full outer join
. Additionally, there is an equivalent method syntax for performing joins using LINQ, which may be more familiar to developers coming from languages like SQL.
gistlibby LogSnag