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

Update nts.md by changing EF version from 9 to 8 #365

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HrlecMatej
Copy link

We are using .NET 8 and Entity Framework Core 8. Directly passing a connecting string for Postgis with Npgsql worked with our current EF version:
builder.Services.AddDbContext<MyContext>(options => options.UseNpgsql( "<connection string>", o => o.UseNetTopologySuite()));

So I propose to change the version of EF mentioned in the docs from 9 to 8.

@roji
Copy link
Member

roji commented Sep 24, 2024

@HrlecMatej prior to version 9.0, you must also manually register the Npgsql plugin in addition to the EF-level configuration. Have you maybe missed the "Older EF versions, with a connection string" tab just next to this?

@HrlecMatej
Copy link
Author

HrlecMatej commented Sep 24, 2024

@roji I only added this snippet of code in my DbContext's OnConfiguring method:
var connectionString = GetConnectionString(); optionsBuilder.UseNpgsql(connectionString, o => o.UseNetTopologySuite());
I verified it worked by saving a Geometry, and later querying if that geometry contains a Point inside. E.g.:
await dbContext.Products.Where(p => p.Geometry.Contains(new Point(8.6854, 50.1107))).ToArrayAsync()

@roji
Copy link
Member

roji commented Sep 24, 2024

@HrlecMatej that shouldn't be working on EF 8.0, you need to have NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite() somewhere in your application. If you think you don't, can you please submit a minimal console program that shows what you're doing exactly?

@HrlecMatej
Copy link
Author

@roji Just to be sure, I did a string search on the solution. Only UseNetTopologySuite is used in optionsBuilder.UseNpgsql(connectionString, o => o.UseNetTopologySuite());
I used to have NpgsqlConnection.GlobalTypeMapper.UseNetTopologySuite() in my solution as well, but I noticed it works without so I deleted it.
I can prep a minimal example in a few days.

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