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

Error when including list of Point #3169

Closed
RousseauRemi opened this issue May 15, 2024 · 6 comments · Fixed by #3339
Closed

Error when including list of Point #3169

RousseauRemi opened this issue May 15, 2024 · 6 comments · Fixed by #3339
Assignees
Labels
bug Something isn't working
Milestone

Comments

@RousseauRemi
Copy link

Dear Team,

I am currently experiencing an exception with a List of Point while utilizing Entity Framework (EF) and PostgreSQL with PostGIS. The issue arose during the transition from .NET 7 to .NET 8, as the functionality was operating correctly in the former. Upon moving to .NET 8, I am unable to retrieve data due to the exception detailed in the related issue: #2975.

To facilitate the reproduction of the problem, I have prepared a minimal repository: https://github.com/workpioupiou/ErrorNpgsql. By executing the command "dotnet ef migrations add Initial --project ErrorNpgsql", the following error is generated:

"Unable to create a 'DbContext' of type ''. The exception 'When building an array mapping over 'Point', the JsonValueReaderWriter for element mapping 'NpgsqlGeometryTypeMapping`1' is incorrect ('NpgsqlJsonGeometryWktReaderWriter' instead of 'NetTopologySuite.Geometries.Point').' was thrown while attempting to create an instance."

As a temporary workaround, I have moved the List of Point into a new class, PositionPoint, which contains an ID and a property point. However, this solution required the deletion of the migrations files and the database.

I would greatly appreciate any insights or potential solutions to resolve this issue without having to delete the migrations files and the database.

public class Zone
{
    public Guid Id { get; set; }
    public List<Point> Positions { get; set; }
}

Become :

public class Zone
{
    public Guid Id { get; set; }
    public List<PositionPoint> Positions { get; set; }
}

public class PositionPoint
{
    public Guid Id { get; set; }
    public Point Position { get; set; }
}

Thank you for your time and assistance.

@hakanderyal
Copy link

hakanderyal commented Jun 24, 2024

I'm also having a similar error related to byte arrays. In my case it's when querying with an optional ULID column with that is mapped to nullable bytea, using Contains. It has the same stack trace with the referenced issue.

System.InvalidOperationException: When building an array mapping over 'Nullable'1', the JsonValueReaderWriter for element mapping 'NpgsqlByteArrayTypeMapping' is incorrect ('JsonConvertedValueReaderWriter'2' instead of 'NUlid.Ulid').
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping.NpgsqlArrayTypeMapping'3.CreateParameters(String storeType, RelationalTypeMapping elementMapping)

It also worked without problems with Npgsql 7/EFCore 7.

Is the repro provided by the OP enough or should I also create one?

// Edit: If anyone else comes across this post before it's fixed (since Google shows this at the top), you can create your own contains expression to get around this, this should help: https://stackoverflow.com/a/9678266/483084

@roddone
Copy link

roddone commented Jul 22, 2024

Hi, any news on this ?

I have the exact same problem and it prevents me to migrate my project correctly in .NET 8 .

@roji
Copy link
Member

roji commented Oct 29, 2024

Thanks for raising this and sorry it took so long to get looked at. I can confirm there's a bug here - I'm pushing a fix and will backport it to the next release of 8.0.x.

@roji roji self-assigned this Oct 29, 2024
@roji roji added the bug Something isn't working label Oct 29, 2024
@roji roji added this to the 8.0.11 milestone Oct 29, 2024
@martin-hirsch
Copy link

@roji, made my day!

roji added a commit to roji/efcore.pg that referenced this issue Oct 29, 2024
@roji
Copy link
Member

roji commented Oct 29, 2024

@hakanderyal I'm not sure your problem is the same as this one... Can you please open a new issue with a repro?

@roji roji closed this as completed in 45c8227 Oct 29, 2024
roji added a commit that referenced this issue Oct 29, 2024
@hakanderyal
Copy link

I believe it's the same issue, it occurs at the same location which you've changed. I'll open a new one if it continues after the release.

Thanks!

WhatzGames pushed a commit to WhatzGames/efcore.pg that referenced this issue Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants