using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace Complex.Infrastructure.Extensions { public static class QueryFilter { public static void ApplyGlobalFilters(this ModelBuilder modelBuilder, string propertyName, T value) { foreach (var entityType in modelBuilder.Model.GetEntityTypes()) { var foundProperty = entityType.FindProperty(propertyName); if (foundProperty != null && foundProperty.ClrType == typeof(T)) { var newParam = Expression.Parameter(entityType.ClrType); var filter = Expression.Lambda(Expression.Equal(Expression.Property(newParam, propertyName), Expression.Constant(value)), newParam); modelBuilder.Entity(entityType.ClrType); } } } } }