Skip to content

Geo support#34

Merged
PhenX merged 16 commits intoPhenX:masterfrom
SebastianStehle:geo-support
May 24, 2025
Merged

Geo support#34
PhenX merged 16 commits intoPhenX:masterfrom
SebastianStehle:geo-support

Conversation

@SebastianStehle
Copy link
Copy Markdown
Collaborator

No description provided.

…workCore.BulkInsert into generic-base-provider

# Conflicts:
#	src/PhenX.EntityFrameworkCore.BulkInsert.MySql/MySqlBulkInsertProvider.cs
#	src/PhenX.EntityFrameworkCore.BulkInsert.PostgreSql/PostgreSqlBulkInsertProvider.cs
#	src/PhenX.EntityFrameworkCore.BulkInsert.SqlServer/SqlServerBulkInsertProvider.cs
#	src/PhenX.EntityFrameworkCore.BulkInsert.Sqlite/SqliteBulkInsertProvider.cs
#	src/PhenX.EntityFrameworkCore.BulkInsert/BulkInsertOptionsExtension.cs
#	src/PhenX.EntityFrameworkCore.BulkInsert/BulkInsertProviderBase.cs
#	src/PhenX.EntityFrameworkCore.BulkInsert/Extensions/PublicExtensions.cs
#	tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Basic/BasicTestsBase.cs
#	tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Basic/BasicTestsMySql.cs
#	tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Basic/BasicTestsPostgreSql.cs
#	tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Basic/BasicTestsSqlServer.cs
#	tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/Tests/Basic/BasicTestsSqlite.cs
@SebastianStehle SebastianStehle requested a review from PhenX as a code owner May 24, 2025 14:36
@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

I have not worked on sqlite yet, but it should look very similar. The problem is to install the binaries here.

@PhenX
Copy link
Copy Markdown
Owner

PhenX commented May 24, 2025

I seems like adding

<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.11" />

To the Tests package makes it work also for Sqlite

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

I don't know what is wrong now. I am really lost. I can't find the damn error :(

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

Okay, I am done.

I have also simplified the test fixtures a little bit and fixed a bug in the metadata provider with multiple contexts. I still have not figured out how to make Sqlite workign locally and in github, but this is probably something for another PR.

@PhenX
Copy link
Copy Markdown
Owner

PhenX commented May 24, 2025

OK I'll review it tonight

@PhenX
Copy link
Copy Markdown
Owner

PhenX commented May 24, 2025

I'm not a big fan of the NetTopologySuite dependency, did you consider resolving a ITypeMappingSource? The one for Sql server for example https://github.com/dotnet/efcore/blob/main/src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

SebastianStehle commented May 24, 2025

I don#t get it. How would you make the conversion then?

The point is the following: Geo is provided by extensions in EF, which do the actual conversion. You have to basically the same to support the correct types. NetTopologySuite seems to be the defacto standard, so largish applications have the dependency anyway.

@PhenX
Copy link
Copy Markdown
Owner

PhenX commented May 24, 2025

Well EF knows how to convert geo types when we call UseNetTopologySuite, so I think we should use these converters

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

How?

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

SebastianStehle commented May 24, 2025

For exmaple we already use this method to get the correct type for postgres:


        var mapping = column.Property.GetRelationalTypeMapping() as NpgsqlTypeMapping;

        return mapping?.NpgsqlDbType;

But for Geography we get no mapping at all.

@PhenX
Copy link
Copy Markdown
Owner

PhenX commented May 24, 2025

At least for NPGSQL, I'll have to check for others, but we can use the mapping to get the underlying NpgsqlDbType, which seems to be different for bulk insert (bytea, seeing your code)

here geo is an instance of Point which inherits Geometry

image

@PhenX
Copy link
Copy Markdown
Owner

PhenX commented May 24, 2025

Let me go further, I'm not sure I went deep enough in your PR

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

Sure, I basically went from error to error. Always got something like "Cannot convert from x to y"

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

e.g. SQL Server accepts geopoints in reverse coordination order (Y, X) not (X, Y)

@PhenX
Copy link
Copy Markdown
Owner

PhenX commented May 24, 2025

Ok, I thought I could find something among mapping sources, but no...

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

There are internal APIs, they are called ProviderConverter, but I could not find any way to get access to them.

@SebastianStehle
Copy link
Copy Markdown
Collaborator Author

A release would be awesome.

@PhenX PhenX merged commit e17ba44 into PhenX:master May 24, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants