using System.Data.Entity;
using System.Collections.Generic;
using Z.EntityFramework.Plus;
public static void Main()
using (var context = new EntityContext())
var list = context.Orders.IncludeFilter(x => x.Items.Where(y => !y.IsSoftDeleted)
foreach(var order in list)
Console.WriteLine("Active order items in {0}: {1}", order.Name, order.Items.Count());
public static void GenerateData()
using (var context = new EntityContext())
context.Orders.Add(new Order() { Name = "Order_A", Date = DateTime.Now.AddDays(-4), IsSoftDeleted = true });
context.Orders.Add(new Order() { Name = "Order_B", Date = DateTime.Now.AddDays(-5), IsSoftDeleted = true });
context.Items.Add(new InvoiceItem() { Date = DateTime.Now.AddDays(-4), IsSoftDeleted = false, Price = 35, OrderId = 1 });
context.Items.Add(new InvoiceItem() { Date = DateTime.Now.AddDays(-4), IsSoftDeleted = false, Price = 22, OrderId = 1 });
context.Items.Add(new InvoiceItem() { Date = DateTime.Now.AddDays(-5), IsSoftDeleted = false, Price = 37, OrderId = 2 });
context.Items.Add(new InvoiceItem() { Date = DateTime.Now.AddDays(-5), IsSoftDeleted = true, Price = 7, OrderId = 2 });
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Order> Orders { get; set; }
public DbSet<InvoiceItem> Items { get; set; }
public int OrderId { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
public bool IsSoftDeleted { get; set; }
public List<InvoiceItem> Items { get; set; }
public int InvoiceItemId { get; set; }
public DateTime Date { get; set; }
public bool IsSoftDeleted { get; set; }
public int Price { get; set; }
public int OrderId { get; set; }