Base solution for your next web application
Open Closed

Filter (search) case insensitive #3216


User avatar
0
riaan created

Hi,

How do I make sure that my filter [https://aspnetzero.com/Documents/Developing-Step-By-Step-Core#filtering-people]) is also case-insensitive (StringComparison.CurrentCultureIgnoreCase)?

Kind regards,

Riaan


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I haven't tried with this Linq to Entities, have you tried it ? If it does not work I suggest you to search it on the internet because this is a topic related to Entity Framework.

    Thanks.

  • User Avatar
    0
    riaan created

    Hi,

    I see that we need to look at making use of the I​Equality​Comparer<​T> Interface because of this being a ASPNETCOREZERO project and Contains() is not part of ASPNET CORE.

    I will investigate the use of IEqualityComparere<T> for string case insensitive compares a bit later, but found the following solution (although not as elegant) to be working in the meantime for case-insensitive filtering:

    var foodNotes = _foodNoteRepository
                    .GetAll()
                    .WhereIf(
                        !input.Filter.IsNullOrEmpty(),
                        p => p.Title.ToLower().Contains(input.Filter.ToLower()) ||
                             p.Detail.ToLower().Contains(input.Filter.ToLower()))
                    .OrderBy(p => p.Title)
                    .ThenBy(p => p.CreationTime)
                    .ToList();
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @riaan,

    Thank you for sharing your solution :)