📜  C# linq include - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:43.886000             🧑  作者: Mango

代码示例1
//If you have a Customer model that contains a list of orders.
//You can include the orders like this
var customersWithOrders = _dbContext.Customers
    .Include(c => c.Orders)
      .ToList();

//Lets say those orders then contain products. You can include those like so:
var customersWithOrdersAndProducts = _dbContext.Customers
    .Include(c => c.Orders)
          .ThenInclude(o => o.Products)
      .ToList();