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


3 Answer(s)
  • User Avatar
    0
    IanW created

    Could you show your code please?

  • 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;
    }
    
  • 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;

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19