Closed sidec15 closed 1 year ago
@sidec15 all of the above is correct, I'm sorry you lost time figuring it out... I never got around to updating the EF docs for using NpgsqlDataSource with the plugins...
I've pushed #292 live to fix that, please take a look and let me know what you think.
@roji now the documentation is perfectly clear. Thank you for replying me in a short time.
I was trying to upgrade Npgsql.EntityFrameworkCore.PostgreSQL and Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite in my Asp.Net Core application from verison 6.x to version 7.x. I tried to use the Datasource as described in the Release notes of Npgsql 7.0. So I implemented something like the following:
In this application I have also Hangfire for the background jobs:
Finally I initialize the database:
When I tried to read data from database that include geometry point type, an exception occurs:
I found a solution after two days that is calling the extension method "UseNetTopologySuite" of NpgsqlDataSourceBuilder:
So basically the method UseNetTopologySuite has to be called two times because if I remove the call "o.UseNetTopologySuite();" in UseNpgsql method, another exception occurs when I initialize the database:
I also tried to avoid using the NpgsqlDataSourceBuilder using the old way:
In this case the error "Can't cast database type . to Point" occurs only if I comment the line of code used to retrieve the DB context:
that is used to initialize the database.
Debugging the exception I found that the error "Can't cast database type . to Point" is thrown when the Npgsql library tries to obtain the TypeMapper for the point column. When the method ResolveHandler of the RowDescriptionMessage class is called, the _typeMapper._resolvers contains only Npgsql.TypeMapping.BuiltInTypeHandlerResolver and not Npgsql.NetTopologySuite.Internal.NetTopologySuiteTypeHandlerResolver.
I think that at least an improvement of the documentation about the usage of UseNetTopologySuite with the NpgsqlDataSourceBuilder must be provided.
I created a simple project to reproduce this behaviour: https://github.com/sidec15/web-app-npgsql.
Steps to reproduce
Using NpgsqlDataSourceBuilder:
Without NpgsqlDataSourceBuilder:
services.AddDbContext(
options => options
.UseNpgsql(dataSource, o =>
{
o.UseNetTopologySuite();
})
.UseSnakeCaseNamingConvention()
);
In Program.cs file comment lines:
Further technical details