npgsql / efcore.pg

Entity Framework Core provider for PostgreSQL
PostgreSQL License
1.52k stars 223 forks source link

Npgsql.PostgresException (0x80004005): 42883: function st_contains(deployment.geometry, deployment.geometry) does not exist #3155

Open flyinseal opened 5 months ago

flyinseal commented 5 months ago

Hi,

I want to query by using postgis extension. I can execute the function in postgresql database. But i fail in .net core project. This is used in an ASP.NET Core 8 application.

Referenced packages: image

Program.cs image

add extension in DbContext modelBuilder.HasPostgresExtension("postgis"); entity image

generate geometry object named as region where is used in method in repository image

query in repository var query = GetQueryable() .Include(e => e.Locations) .ThenInclude(e => e.PowerUnits) .WhereIf(region != null, e => e.PowerUnits.Any(p => region!.Contains(p.Coordinates)));

error: image

Is there something wrong in my code? Could you kindly please help me?

roji commented 5 months ago

Can you please submit a minimal, runnable project or code sample that shows the problem happening? It's difficult to reconstruct a problem from a bunch of snippets and screenshots as above.

flyinseal commented 5 months ago

Of course!

generate geometry parameter in service image

call repository to query image even i use the native sql to query, but it doesn't work

DbContext image this extension is used in a new schema under the database named as deployment

Related Entity image

Program.cs image

This is all the codes related with this issue. Besides, I have already executed below sql in database. image the last sql can be executed in database and cannot be executed through codes. same error like "ST_Point doesn't exist" image

flyinseal commented 5 months ago

I probably find the reason. However, I don't know how to solve it with EF core. I need to call the function under the schema "deployment". But the generated SQL doesn't include the "deployment" schema! Am I right? If so, how to specify the schema when I use the contains or within method. I already add default schema in DbContext like below: image

image

roji commented 5 months ago

@flyinseal as a general rule, please don't post screenshots of code when reporting issues. As the maintainer, there's very little I can do with screenshots - I can't copy and paste your code, and it's frequently also very hard to actually read it (because the text is very small). Please go through the effort of actually producing a minimal, runnable code sample - like a simple console program, that, when executed, produces the problem.

I'm asking for this since I'm currently unable to reproduce your problem. And in 90% of cases, when users actually make the effort of creating a minimal repro, they run into some issue in their own code which caused the problem.