Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation translation for List<T> #395

Closed
roji opened this issue May 9, 2018 · 11 comments · Fixed by #1185
Closed

Operation translation for List<T> #395

roji opened this issue May 9, 2018 · 11 comments · Fixed by #1185
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@roji
Copy link
Member

roji commented May 9, 2018

We now support mapping CLR List<T> to PostgreSQL arrays (#392). We also have some nice operation translations for regular CLR arrays, but should also translate operations for List<T>, which is supported for mapping PostgreSQL arrays.

@roji roji added the enhancement New feature or request label May 9, 2018
@roji roji added this to the 2.1.0 milestone May 13, 2018
@austindrenski
Copy link
Contributor

@roji Has anyone started working on this?

If not, I can start scoping out what we could translate in time for 2.1.

@roji
Copy link
Member Author

roji commented May 27, 2018

Feel free to work on this, at least some things should be fairly easy. As a first goal it would be good to achieve party with what is already translated for arrays (length, indexing...)

@roji
Copy link
Member Author

roji commented Jan 1, 2020

See some work done based on the old query pipeline in #541

@roji roji assigned roji and unassigned austindrenski Jan 6, 2020
roji added a commit that referenced this issue Jan 6, 2020
* Match our List<T> translation capabilities to CLR array.
* Improve some mapping and inference aspects.

Closes #395
roji added a commit that referenced this issue Jan 6, 2020
* Match our List<T> translation capabilities to CLR array.
* Improve some mapping and inference aspects.

Closes #395
roji added a commit that referenced this issue Jan 6, 2020
* Match our List<T> translation capabilities to CLR array.
* Improve some mapping and inference aspects.

Closes #395
roji added a commit that referenced this issue Jan 10, 2020
* Match our List<T> translation capabilities to CLR array.
* Improve some mapping and inference aspects.

Closes #395
roji added a commit that referenced this issue Jan 10, 2020
* Match our List<T> translation capabilities to CLR array.
* Improve some mapping and inference aspects.

Closes #395
roji added a commit that referenced this issue Jan 10, 2020
* Match our List<T> translation capabilities to CLR array.
* Improve some mapping and inference aspects.

Closes #395
@ryanelian
Copy link

ryanelian commented Feb 23, 2020

Excuse me, does this mean that:

            var origins = new List<string> { origin };

            var results = DB.Clients
                .Where(Q => origins.All(item => Q.AllowedCorsOrigins.Contains(item)))
                .AsNoTracking()
                .AnyAsync();

Is now supported?

(Will it translate to:)

SELECT * FROM mytable WHERE myarray @> ARRAY['item'];

@roji
Copy link
Member Author

roji commented Feb 23, 2020

@ryanelian yes, that should work - it's very similar to this test. Give it a try and please open a new issue if you run into trouble.

@JohnDitno
Copy link

JohnDitno commented Oct 1, 2020

Could someone confirm whether the following partial matching using Any and Contains is supported?

var partialOrigin = "http://";

var results = DB.Clients
.Where(Q => Q.origins.Any(item => item.Contains(partialOrigin)))
.AsNoTracking()
 .AnyAsync();

@roji
Copy link
Member Author

roji commented Oct 3, 2020

@JohnDitno take a look at #395 (comment). I'd recommend trying to reference 5.0.0-rc1 and giving it a try to be sure.

@SommerEngineering
Copy link

SommerEngineering commented Oct 29, 2020

@JohnDitno Unfortunately it does not work, at least in our case:

The LINQ expression 'DbSet<Entry>()
    .Where(e => e.IsLatestRevision)
    .Where(e => e.EditTime >= __request_ShowSince_0)
    .Where(e => !(e.IsArchived))
    .Where(e => !(e.IsDeleted))
    .OrderBy(e => e.Name)
    .Where(e => e.Competencies
        .Any(i => i.Contains(__searchTerm_1)))' could not be translated.

It does not matter if Entry.Competencies is List<string> or string[]. Both fails with the shown exception.

I used:

  • .NET 5.0 RC2 and <TargetFramework>net5.0</TargetFramework>
  • <PackageReference Include="Npgsql" Version="5.0.0-preview1" />
  • <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0-rc2" />
  • PostgreSQL 12.2 server

@ryanelian Should I open a new issue for that?

@JohnDitno
Copy link

@SommerEngineering thanks for responding to my query.

That is a shame it doesn't seem to work still, hopefully it can be fixed as we have a similar scenario to your case.

@roji
Copy link
Member Author

roji commented Oct 29, 2020

@SommerEngineering your query is very different from a simple Contains in a Where clause - can you please open a new issue?

If Competencies is a list (or array) of string, are you searching whether one of its strings contains a specific character? Posting a full code sample (including your model) could help clarify what you're trying to do.

@SommerEngineering
Copy link

Thanks @roji for your response. I created issue #1554 with a minimal repo to reproduce the case 🙂

@JohnDitno In my repo for issue #1554 you find different attempts to archive this functionality. No one works, if partial matching is necessary. Searching for exact matches in array columns works, though. This is might a workaround until we get the issue solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants