1
我有這個lambda表達式其實際工作C#拉姆達與加入和GROUPBY
var d = DateTime.Now.AddDays(-30);
return db.Orders
.Where(o => o.CreateDate > d)
.Join(db.OrderItems, o => o.OrderId, o => o.OrderId, (o, p) => new { Order = o, OrderItem = p })
.Join(db.Customers, o => o.Order.CustomerId, o => o.CustomerId, (o, p) => new { o.Order, o.OrderItem, Customer = p })
.Where(o => o.Order.Status > 3)
.GroupBy(o => o.Customer.CustomerId)
.Select(o => new CustomerMonthSale
{
CustomerId = o.Key,
Price = o.Sum(p => p.OrderItem.Price * p.OrderItem.Quantity),
//Name = o.Select(p => p.Customer.Name)
})
.OrderByDescending(o => o.Price)
.Take(10).ToList();
但我有這個註釋行問題。我收到錯誤消息:
無法隱式轉換類型 'System.Collections.Generic.IEnumerable' 到 '字符串'
爲什麼?我該如何解決?