using System.Data.Entity;
using System.Collections.Generic;
using Z.EntityFramework.Plus;
public static void Main()
using (var context = new EntityContext())
context.Filter<Category>(q => q.Where(x => !x.IsSoftDeleted));
var categories = context.Categories.ToList();
FiddleHelper.WriteTable(categories);
public static void GenerateData()
using (var context = new EntityContext())
context.Categories.Add(new Category() { Name = "Category_A", IsSoftDeleted = false});
context.Categories.Add(new Category() { Name = "Category_B", IsSoftDeleted = true });
context.Categories.Add(new Category() { Name = "Category_C", IsSoftDeleted = false });
context.Products.Add(new Product() { Name = "Product_A", CategoryId = 1 });
context.Products.Add(new Product() { Name = "Product_B", CategoryId = 2 });
context.Products.Add(new Product() { Name = "Product_C", CategoryId = 1 });
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public int ProductId { get; set; }
public string Name { get; set; }
public int CategoryId { get; set; }
public int CategoryId { get; set; }
public string Name { get; set; }
public bool IsSoftDeleted { get; set; }