我正在尝试根据时间戳获取每个客户的第一个订单。
下面是一些不编译的伪代码:
var minOrders = (from Orders in DataSet.Orders select Orders.OrderTimestamp).Min()
join Customers in DataSet.Customers on Orders.CustomerId equals Customers.CustomerId
select new
{
Customers.Name,
Orders.OrderAmount
});
关于正确的LINQ结构的任何指针都会很棒,谢谢。
乔
答案 0 :(得分:3)
根据您编写的代码,我想您需要每个客户的第一个订单
您的陈述将是
var minOrders = from customer in DataSet.Customers
let order = (from o in DataSet.Orders
where o.CustomerId == customer.CustomerId
order by o.OrderTimestamp
select o).first()
select new
{
customer.Name,
order.OrderAmount
});