I want to include the isDeleted
values in the database to my index when the user is an admin. I used the global query filter to filter the data.
This is the code I have:
var param = Expression.Parameter(entity.ClrType);
var propertyMethodInfo = typeof(EF).GetMethod("Property").MakeGenericMethod(typeof(bool));
var isDeleted = Expression.Call(propertyMethodInfo, param, Expression.Constant("IsDeleted"));
BinaryExpression compareExpression = Expression.MakeBinary(ExpressionType.Equal, isDeleted, Expression.Constant(false));
var lambdaExpression = Expression.Lambda(compareExpression, param);
builder.Entity(entity.ClrType).HasQueryFilter(lambdaExpression);