using System.Collections.Generic;
using System.Data.Entity;
using Z.EntityFramework.Plus;
public static void Main()
using (var context = new EntityContext())
var query = context.Customers.IncludeFilter(x => x.Invoices.Where(y => !y.IsSoftDeleted))
.IncludeFilter(x => x.Invoices.Where(y => !y.IsSoftDeleted)
.Select(y => y.InvoiceItems.Where(z => !z.IsSoftDeleted)));
FiddleHelper.WriteTable("InvoiceItems", query.ToList().SelectMany( x => x.Invoices.SelectMany(z => z.InvoiceItems)));
public static void GenerateData()
List<Customer> list = new List<Customer>() {
new Customer() { Invoices = new List<Invoice>() {
new Invoice() { Description = "Invoice_A", IsSoftDeleted = false , InvoiceItems = new List<InvoiceItem>() { new InvoiceItem() { Description = "Invoice_A_InvoiceItem_A", IsSoftDeleted = false } ,
new InvoiceItem() { Description = "Invoice_A_InvoiceItem_B", IsSoftDeleted = true }}},
new Invoice() { Description = "Invoice_B", IsSoftDeleted = true , InvoiceItems = new List<InvoiceItem>() { new InvoiceItem() { Description = "Invoice_B_InvoiceItem_A", IsSoftDeleted = false } ,
new InvoiceItem() { Description = "Invoice_B_InvoiceItem_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<InvoiceItem> InvoiceItems { 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 List<InvoiceItem> InvoiceItems { get; set; }
public bool IsSoftDeleted { get; set; }
public int InvoiceItemID { get; set; }
public string Description { get; set; }
public bool IsSoftDeleted { get; set; }