Skip to content

Translating LIKE ANY #422

Closed
Closed

Description

@austindrenski

Does EF Core/Npgsql have a way to translate a LIKE ANY statement?

For example, translating from this:

IQueryable<string> source; // => "cat"
string[] items = new string[] { "a", "b", "c" };

source.Where(x => items.Any(x.StartsWith));

to this:

WHERE 'cat' LIKE ANY('{a%,b%,c%}');

Activity

  1. roji commented on May 23, 2018

    @roji
    Member

    Not at the moment, that would indeed be a useful feature...

    You could translate StartsWith(), EndWith() and EF.Functions.Like() for full-fledged patterns. The last one will probably be easiest since IIRC StartsWith() and EndsWith() are a bit more complicated than they look - see the relevant translators.

  2. austindrenski commented on May 23, 2018

    @austindrenski
    ContributorAuthor

    Sounds good. I'll open a PR and see what I can do with the translation.

  3. removed
    good first issue
    on May 29, 2018
  4. added this to the 2.1.0 milestone on May 29, 2018
  5. roji commented on May 29, 2018

    @roji
    Member

    Thanks @austindrenski, merged your contribution for LIKE ANY and LIKE ALL. I've opened #436 for {Starts,Ends}With() support.

  6. Andrioden commented on Jan 8, 2019

    @Andrioden

    @roji : I think you should document this.

    It was not obvious to me that I could do source.Where(x => collection.Any(y => EF.Functions.Like(x.SomeString, y)));. Beautifully solved, thou I am a bit sad it took me 1-2 hours finding this issue and digging into the pull request to realise how it was possible. : P

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions