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

Using geography[] mapped to a List<Point> on entity for requests #2722

Closed
ElysaSrc opened this issue Apr 17, 2023 · 5 comments
Closed

Using geography[] mapped to a List<Point> on entity for requests #2722

ElysaSrc opened this issue Apr 17, 2023 · 5 comments

Comments

@ElysaSrc
Copy link

I'm having trouble to use npgsql with a edge-case that seems to touch the limitation of the translation capabilities.
I have a geography[] mapped to a List<Point> and I want to list all entities that will match the predicate that given a Polygon I want all entities with at least a point that intersects.

I'm having the following property on an entity:

[Required]
[Column(TypeName = "geography[]")]
public List<Point> Locations { get; set; } = new();

And I'm requesting it the following way:

dbC.MapEntityCaches.Where(mec => mec.Locations.Any(l => b.Polygon.Intersects(l)));

I'm having the following error message:

System.InvalidOperationException: The LINQ expression 'l => __b_Polygon_0.Intersects(l)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by insertin
g a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

Is this a bug on npgsql or am I requesting it incorrectly ?

@roji
Copy link
Member

roji commented Apr 17, 2023

This is indeed not currently supported; in general, translating arbitrary LINQ operators (such as Any above) over primitive collections is covered by dotnet/efcore#30426, which I'm currently working on for EF Core 8.0. Though geometry collections specifically may pose some additional complications: see dotnet/efcore#30630 for some thoughts on generally representing collections of geometries in databases, /cc @ajcvickers (we just had a discussion around this).

To help us design things better, are you aware of the GeometryCollection type, which is a specialized type for representing collections of geometries? Can you provide some context on why you chose to use List<Point> rather than that?

@ElysaSrc
Copy link
Author

I wasn't aware of the GeometryCollection type, and it did fixed my issue. I do not have a use-case that requires a List<Point> specifically.

Thank you for your help.

@roji
Copy link
Member

roji commented Apr 17, 2023

That's good to hear, but how exactly did it fix your issue? IIRC Any with Intersect isn't yet working on GeometryCollection either...

@ElysaSrc
Copy link
Author

I defined the Points of the entity this way :

public GeometryCollection? Points { get; set; }

And I am querying this way:

var query = dbContext.MapEntityCaches.Where(mec => b.Polygon.Intersects(mec.Points));

The results are consistent so it seems it's working.

@roji
Copy link
Member

roji commented Apr 17, 2023

OK thanks, yeah - that makes sense. Am going to close this as the problem has been resolved, but see related conversation in dotnet/efcore#30630.

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants