Skip to content

Support string.Contains(String, StringComparison) overload #1498

Closed as duplicate

Description

@fagnercarvalho

I migrated from MariaDB to PostgreSQL and in MariaDB I was doing case insensitive contains queries like this:

l.Name.Contains(currentFilter, StringComparison.OrdinalIgnoreCase)

However when I migrated to Npgsql.EntityFrameworkCore.PostgreSQL I have to use this:

EF.Functions.ILike(l.Name, $"%{currentFilter}%")

Is it possible to support the overload for string.Contains instead of having to call this method?

Thank you!

Activity

  1. roji commented on Sep 12, 2020

    @roji
    Member

    See dotnet/efcore#1222 for a full discussion on this. The summary is that string operations which accept StringComparison are not translated in EF Core, for various reasons - it's very easy to cause indexes not to get used (very bad for perf), and in many cases a specific collation needs to be specified by the user - just saying "insensitive" isn't specific enough (for PG ILike this doesn't necessary hold, but still).

    Take a look at the docs around case sensitivity and collations. If you're OK with trying out the latest 5.0.0 preview (very stable, 5.0.0 is about to be released), consider defining a case-insensitive collation on your Name column - this would help with index usage (though probably not with most Contains operations). Otherwise just using ILike or citext could work.

    Note that in the code above, if currentFilter happens to contain one of the wildcards (%, _) you'll probably get incorrect results.

  2. roji commented on Sep 12, 2020

    @roji
    Member

    Duplicate of dotnet/efcore#1222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions