using Z.EntityFramework.Plus;
using Microsoft.EntityFrameworkCore;
using Microsoft.Data.SqlClient;
using System.Collections.Generic;
public static void Main()
using (var context = new EntityContext())
context.Database.EnsureCreated();
using (var context = new EntityContext())
context.Filter<Post>(MyEnum.EnumValue1, q => q.Where(x => !x.IsSoftDeleted)).Disable();
var list = context.Posts.Filter(MyEnum.EnumValue1).ToList();
FiddleHelper.WriteTable("After Filtering", list);
public static void GenerateData()
using (var context = new EntityContext())
context.Posts.Add(new Post() {Title = "Post_A", IsSoftDeleted = false, ViewCount = 12});
context.Posts.Add(new Post() {Title = "Post_B", IsSoftDeleted = true, ViewCount = 41});
context.Posts.Add(new Post() {Title = "Post_C", IsSoftDeleted = false, ViewCount = 24});
using (var context = new EntityContext())
FiddleHelper.WriteTable("Before Filtering", context.Posts.ToList());
public class EntityContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
public DbSet<Post> Posts { get; set; }
public int PostId { get; set; }
public string Title { get; set; }
public bool IsSoftDeleted { get; set; }
public int ViewCount { get; set; }