我在VB中有以下查询,但我不知道如何将其翻译为C#synatax
Dim q = From c In db.Customers
Group Join o In db.Orders On c.CustomerID Equals o.CustomerID Into orders = Group
Select New With {c.ContactName, .OrderCount = orders.Count()}
谢谢
答案 0 :(得分:4)
实际上很容易。你只需要删除“组”:
var q = from c in db.Customers
join o in db.Orders on c.CustomerID equals o.CustomerID into orders
select new { c.ContactName, OrderCount = orders.Count() };
或者,如果您正在寻找lambda语法:
var q = db.Customers.GroupJoin(db.Orders,
o => o.CustomerID,
c => c.CustomerID,
(c, orders) =>
new
{
c.ContactName,
OrderCount = orders.Count()
});
答案 1 :(得分:1)
Dim q = From c In db.Customers
Group Join o In db.Orders On c.CustomerID Equals o.CustomerID Into orders = Group
Select New With {c.ContactName, .OrderCount = orders.Count()}
var q =
from c in db.Customers
join o in db.Orders on c.CustomerID equals o.CustomerID into orders
select new {c.ContactName, .OrderCount = orders.Count()};