using System.Collections.Generic;
using System.Data.Entity;
using Z.EntityFramework.Plus;
public static void Main()
QueryIncludeOptimizedManager.AllowQueryBatch = false;
using (var context = new EntityContext())
var query = context.Customers.IncludeOptimized(x => x.Invoices.Where(y => !y.IsSoftDeleted));
FiddleHelper.WriteTable("Invoices", query.ToList().SelectMany(x => x.Invoices));
public static void GenerateData()
List<Customer> list = new List<Customer>() {
new Customer() { Invoices = new List<Invoice>() {
new Invoice() { Description = "Invoice_A", IsSoftDeleted = false },
new Invoice() { Description = "Invoice_B", IsSoftDeleted = true }}
using (var context = new EntityContext())
context.BulkInsert(list, options => options.IncludeGraph = true);
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Invoice> Invoices { get; set; }
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<Invoice> Invoices { get; set; }
public int InvoiceID { get; set; }
public string Description { get; set; }
public bool IsSoftDeleted { get; set; }