我有一个面试问题但无法完成它&我想知道正确的答案。
public interface ICustomer
{
string Name { get; }
IEnumerable<IOrder> Orders { get; }
}
public interface IOrder
{
IEnumerable<IOrderItem> OrderItems { get; }
}
public interface IOrderItem
{
IEnumerable<IProduct> Products { get; }
}
public interface IProduct
{
string Name { get; }
}
public class CustomersController : ApiController
{
public IEnumerable<IOrderItem> List(ICustomer customer)
{
// Return All OrderItems for all orders
}
}
答案 0 :(得分:5)
您可以使用SelectMany
return customer.Orders.SelectMany(o => o.OrderItems);