I have two tables Customers, Orders
Customers CustomerID FName LName
Orders OrderId CustomerID OrderDate
I want to make a linq statement that can join these two tables and get
FName, LName, Count of orders for each customer
I have two tables Customers, Orders
Customers CustomerID FName LName
Orders OrderId CustomerID OrderDate
I want to make a linq statement that can join these two tables and get
FName, LName, Count of orders for each customer
from c in Customers
join o in Orders on c.CustomerID equals o.CustomerID into g
select new { c.FName, c.LName, Count=g.Count() }
from c in db.Customers
let theCount = c.Orders.Count()
select new {c.FName, c.LName, theCount}
http://msdn.microsoft.com/en-us/library/bb425822.aspx#linqtosql_topic11
These access operations translate to more complicated joins or correlated sub-queries in the equivalent SQL, allowing you to walk through your object graph during a query.