我如何对这个查询进行分组?
How i can group this query?
我想按 order.orderID 分组。
可能吗?
我尝试但我做不到。
有什么想法吗?
var query = from order in mydb.Orders
join customer in mydb.Customers on order.CustomerID equals customer.CustomerID
join employee in mydb.Employees on order.EmployeeID equals employee.EmployeeID
join shipper in mydb.Shippers on order.ShipVia equals shipper.ShipperID
join orderdetail in mydb.Order_Details on order.OrderID equals orderdetail.OrderID
join product in mydb.Products on orderdetail.ProductID equals product.ProductID
select new
{
OrderID = order.OrderID,
CustomerName = customer.CompanyName,
EmployeeName = employee.FirstName,
ShipperName = shipper.CompanyName,
Products = product.ProductName,
TotalPrice = orderdetail.UnitPrice * orderdetail.Quantity
};
只需通过 query continuation:
在表达式末尾添加一个 group by
子句
var query = from order in mydb.Orders
join customer in mydb.Customers on order.CustomerID equals customer.CustomerID
[…]
select new {
OrderID = order.OrderID,
CustomerName = customer.CompanyName,
[…]
}
into result
group result by result.OrderId;
我想按 order.orderID 分组。 可能吗? 我尝试但我做不到。 有什么想法吗?
var query = from order in mydb.Orders
join customer in mydb.Customers on order.CustomerID equals customer.CustomerID
join employee in mydb.Employees on order.EmployeeID equals employee.EmployeeID
join shipper in mydb.Shippers on order.ShipVia equals shipper.ShipperID
join orderdetail in mydb.Order_Details on order.OrderID equals orderdetail.OrderID
join product in mydb.Products on orderdetail.ProductID equals product.ProductID
select new
{
OrderID = order.OrderID,
CustomerName = customer.CompanyName,
EmployeeName = employee.FirstName,
ShipperName = shipper.CompanyName,
Products = product.ProductName,
TotalPrice = orderdetail.UnitPrice * orderdetail.Quantity
};
只需通过 query continuation:
在表达式末尾添加一个group by
子句
var query = from order in mydb.Orders
join customer in mydb.Customers on order.CustomerID equals customer.CustomerID
[…]
select new {
OrderID = order.OrderID,
CustomerName = customer.CompanyName,
[…]
}
into result
group result by result.OrderId;