Linq to join two tables and get a score from one table value from another

I have two tables Customers, Orders

Clients User ID FName LName

Orders Order number Custom ID OrderDate

I want to make a linq statement that can join these two tables and get
FName, LName, the number of orders for each client

+6
sql lambda linq
source share
2 answers
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() } 
+6
source share
 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 move to more complex joins or correlated subqueries in equivalent SQL , allowing you to view the graph of objects at the time of the query.

+2
source share

All Articles