using System.Data.Entity;
public static int CurrentRoleId = 1;
public static void Main()
using (var context = new EntityContext())
var list = context.Customers.ToList();
FiddleHelper.WriteTable("Customers", list);
public static void GenerateData()
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Type = CustomerType.Employee, Name = "Customer_A", Description = "Description" });
context.Customers.Add(new Customer() { Type = CustomerType.Web, Name = "Customer_B", Description = "Description", IsDeleted = true });
context.Customers.Add(new Customer() { Type = CustomerType.Web, Name = "Customer_C", Description = "Description" });
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
this.Configuration.QueryFilter.Filter<ISoftDelete>(customer => !customer.IsDeleted || CurrentRoleId == 1);
this.Configuration.QueryFilter.Filter<Customer>(customer => customer.Type == CustomerType.Web || CurrentRoleId == 1);
public DbSet<Customer> Customers { get; set; }
public interface ISoftDelete
bool IsDeleted { get; set; }
public class Customer : ISoftDelete
public int CustomerID { get; set; }
public CustomerType Type { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsDeleted { get; set; }