Skip to content

Translate Array.Take(n).SequenceEquals(foo) #3633

@InspiringCode

Description

@InspiringCode

I have a class with an array property:

public class Part {
    public int Id { get; set; }
    public int[] TaxonomyPath { get; set; }
}

Now I want to query for all Parts where TaxonomyPath starts with [1, 2]:

int[] expected = [1, 2];
await dbContext.Parts
    .Where(x => x.TaxonomyPath.Take(2).SequenceEquals(expected))
    .ToArrayAsync();

I expect this to translate to WHERE "TaxonomyPath"[1:2] = ARRAY[1,2]. Unfortunately this query can't be translated by Npgsql.EntityFrameworkCore.PostgreSQL 9.0.4.

The interesting thing is that Take(2) alone can be translated, and SequenceEquals alone can also be translated.

Is there any way to work around this limitations until this gets fixed (except restored to RawSql)?

I think this is really useful for working with hierarchical tree-like data!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions