using System.Data.Entity;
using System.Collections.Generic;
using Z.EntityFramework.Plus;
public static void Main()
using (var context = new EntityContext())
context.Filter<IApplication>(q => q.Where(x => x.ApplicationId == myApplicationID));
var list = context.Invoices.Where(x => x.CustomerId == myCustomerID).ToList();
FiddleHelper.WriteTable(list);
public static void GenerateData()
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name = "Customer_A", ApplicationId = 3 });
context.Customers.Add(new Customer() { Name = "Customer_B", ApplicationId = 9 });
context.Customers.Add(new Customer() { Name = "Customer_B", ApplicationId = 5 });
context.Invoices.Add(new Invoice() { Date = DateTime.Now.AddDays(-3), CustomerId = 1 });
context.Invoices.Add(new Invoice() { Date = DateTime.Now.AddDays(4), CustomerId = 2 });
context.Invoices.Add(new Invoice() { Date = DateTime.Now.AddDays(1), CustomerId = 2 });
context.Invoices.Add(new Invoice() { Date = DateTime.Now.AddDays(1), CustomerId = 3 });
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Customer> Customers { get; set; }
public DbSet<Invoice> Invoices { get; set; }
public interface IApplication
int ApplicationId { get; set; }
public class Customer : IApplication
public int CustomerId { get; set; }
public string Name { get; set; }
public int ApplicationId { get; set; }
public List<Invoice> Invoices { get; set; }
public int InvoiceId { get; set; }
public DateTime Date { get; set; }
public int CustomerId { get; set; }