question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Contains fails translation when the array is a scalar sbuquery

See original GitHub issue

Hi there.

I’m using Npgsql.EntityFrameworkCore.PostgreSQL v. 5.0.2

I have a property on an entity which is a list of UserIds (guids) that have read a specific message.

public string[] ReadByParticipantIds { get; set; }

In an OrderByDescending() call I need to find out whether it contains the specific user calling (to get unread messages at the top).

According to this https://www.npgsql.org/efcore/mapping/array.html#operation-translation I should be able to do this. However, I’ve tried just about anything on that list and I keep getting errors.

.ReadByParticipantIds.Contains(userId) and .ReadByParticipantIds.Any(s => s == userId) Both returns the following error:

Npgsql.PostgresException (0x80004005): 42883: operator does not exist: text = text[]

I’ve even tried dropping the equality and using .Any() with the various LIKE-translated expressions. That just changed the error to text ~~~ text[] instead.

It seems like the mapper tries to create an expression where we do equality on a string and an array of strings. I.e. on the root of the .Contains() or .Any() expression rather on the content.

Am I doing something wrong or is this a plain bug?

I do have a modelbuilder expression on this field, but that should only be activated when the DB is not PostGres. So I doubt that could be the culprit:

modelBuilder.Entity<Message>(b =>
            {
                if (!Database.IsNpgsql())
                {
                    b.Property(p => p.ReadByParticipantIds)
                        .HasConversion(
                            v => string.Join("'", v),
                            v => v.Split(',', StringSplitOptions.RemoveEmptyEntries));
                }
            });

The reason for the above is that I use an in-memory DB for running unit tests.

  • Dan

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Dan-Truecommented, Apr 21, 2021

@roji It seems to work perfectly 😃 I can remove my ugly hack.

0reactions
rojicommented, Apr 21, 2021

Great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Scalar subquery produced more than one element" error ...
I keep getting the error: Scalar subquery produced more than one element. I have tried putting ARRAY in front of each SELECT (which...
Read more >
Subqueries | BigQuery
Scalar subqueries are often used in the SELECT list or WHERE clause. A scalar subquery must select a single column. Trying to select...
Read more >
Scalar Subqueries - MariaDB Knowledge Base
A scalar subquery is a subquery that returns a single value. This is the simplest form of a subquery, and can be used...
Read more >
Subquery examples - Amazon Redshift
This subquery is scalar: it returns only one column and one value, which is repeated in the result for each row that is...
Read more >
Nested data limitations - Amazon Redshift
The following limitations apply to nested data: An array can only contain scalars or struct types. Array types can't contain array or map...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found