using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading.Tasks;
public static async Task Main()
var options = new DbContextOptionsBuilder<MyContext>().UseSqlServer(FiddleHelper.GetConnectionStringSqlServerNorthwind()).Options;
using (var ctx = new MyContext(options))
var withoutIncludeCondition = await ctx.Customers.Where(x => x.CustomerID == "VINET").Include(x => x.Orders).FirstOrDefaultAsync();
var withIncludeCondition = await ctx.Customers.Where(x => x.CustomerID == "VINET").Include(x => x.Orders.Where(y => y.ShipVia == 2)).FirstOrDefaultAsync();
FiddleHelper.WriteTable("WithoutIncludeCondition", withoutIncludeCondition.Orders);
FiddleHelper.WriteTable("WithIncludeCondition", withIncludeCondition.Orders);
public class MyContext : DbContext
public MyContext(DbContextOptions<MyContext> options): base(options)
public DbSet<Order> Orders { get; set; }
public DbSet<Customer> Customers { get; set; }
public int OrderID { get; set; }
public string CustomerID { get; set; }
public Customer Customer { get; set; }
public decimal Freight { get; set; }
public int ShipVia { get; set; }
public string CustomerID { get; set;}
public string ContactName { get; set; }
public List<Order> Orders { get; set; } = new List<Order>();