Open Closed

Data Filtering #6419


User avatar
0
TMuska created
  • ABP Framework version: v7.4.4
  • UI Type: Angular
  • Database System: EF Core
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

Can you give me an example to override the CreateFilterExpression method using a string value for the query filter? Your example is using a bool. I want to have a global query filter that will filter by customer number, just like a tenant id. I followed your example but not able to get it to work with a string.

https://docs.abp.io/en/abp/latest/Data-Filtering

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

3 Answer(s)
  • User Avatar
    0
    IanW created

    Could you show your code please?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    TMuska created

    I'm just trying to follow the example. Instead of IsActive/boolean, I'm trying to do CustomerNumber/string.

    protected override Expression<Func<TEntity, bool>> CreateFilterExpression<TEntity>()
    {
        var expression = base.CreateFilterExpression<TEntity>();
    
        if (typeof(IIsActive).IsAssignableFrom(typeof(TEntity)))
        {
            Expression<Func<TEntity, bool>> isActiveFilter =
                e => !IsActiveFilterEnabled || EF.Property<bool>(e, "IsActive");
            expression = expression == null 
                ? isActiveFilter 
                : QueryFilterExpressionHelper.CombineExpressions(expression, isActiveFilter);
        }
    
        return expression;
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The expression must be Expression<Func<TEntity, bool>> If you have a string column you can try to

    Expression<Func<TEntity, bool>> myStringFilter = e => !IsMyFilterEnabled || EF.Property<string>(e, "MyString") == CurrentString;

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.