We're trying to port a .NET 4.5.2 project to 5.0.
My particular problem is to get the spatial queries to work. The existing code makes extensive use of the System.Data.Entity.Spatial.DbGeometry type, which doesn't seem to be available in .NET 5.0.
Looking around, the advice, when running against SqlServer, is to use the NetTopologySuite, which is easy enough because we're already using this.
Instructions are here:
To enable mapping to spatial types via NTS, call the UseNetTopologySuite method on the provider's DbContext options builder. For example, with SQL Server you'd call it like this.
options.UseSqlServer(
@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=WideWorldImporters",
x => x.UseNetTopologySuite());
My problem is that we're not calling options.UseSqlServer. At this point in our journey, we're using try-convert to move our projects from .NET 4.5 to .NET 5.0, and this doesn't configure EntityFramework using options.UseSqlServer(), it's still configuring things with app.config files.
For this project, our EF is configured with this:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<!-- -->
</connectionStrings>
<appSettings>
<!-- -->
</appSettings>
<entityFramework codeConfigurationType="ourcustom.DbConfigurator, ourassembly">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
Any ideas as to how we configure EF to use NTS types for geospatial data?
===
From the comments:
You cannot mix EF Core and EF Classic. – ErikEJ 6 mins ago
That does seem to be exactly what we are doing.
We're using Entity Framework 6.4.0, in our .NET 5.0 project, and the documentation page I was referencing was with respect to Entity Framework Core.
Which may invalidate the whole approach. I cannot configure EF Classic to use NTS types for spatial data.
But it still leaves us with the underlying problem.
Anytime we try to access Microsoft.SqlServer.Types objects we get an exception:
System.InvalidOperationException: Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found.
And we still need to be able to do spatial queries.
What are our options?