I have an asp.net mvc 5 web api application where I need to convert a SqlGeography
instance into a DbGeography
instance for querying with Entity Framework 6. I'm using the following code to do so:
SqlGeography geo = SqlGeography.STGeomFromText(chars, Constants.SRID);
DbGeography dbGeo = DbSpatialServices.Default.GeographyFromProviderValue(geo);
The call to GeographyFromProviderValue
throws the following exception:
The specified provider value is not compatible with this spatial services implementation. A value is required of type 'Microsoft.SqlServer.Types.SqlGeography, Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'.
Parameter name: providerValue
Sure enough, my SqlGeography
instance is coming from the SQL Server 2014 types assembly (Microsoft.SqlServer.Types, Version 12.0.0.0
).
Digging into the Entity Framework source code shows this method to be the culprit:
//EntityFramework.SqlServer.dll(6.0.0.0) System.Data.Entity.SqlServer.SqlTypesAssemblyLoader
public SqlTypesAssemblyLoader(IEnumerable<string> assemblyNames = null)
{
this._preferredSqlTypesAssemblies = (assemblyNames ?? ((IEnumerable<string>)new string[]
{
"Microsoft.SqlServer.Types, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91",
"Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
}));
this._latestVersion = new Lazy<SqlTypesAssembly>(new Func<SqlTypesAssembly>(this.BindToLatest), true);
}
}
As you can see, the types assembly for SQL Server 2014 is not included. Does this mean that Entity Framework 6 does not support types from SQL Server 2014?
Obviously I could find the Types assembly for SQL Server 2012 and use that instead, but I'd rather not have to. Is there any other way around this issue?
Versions 6.0, 6.1, 6.2, and 6.3 are no longer supported. Although Entity Framework 6. x is still supported, it is no longer being developed and will only receive fixes for security issues.
NET Framework, as Entity Framework 6 doesn't support . NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core. The recommended way to use Entity Framework 6 in an ASP.NET Core application is to put the EF6 context and model classes in a class library project that targets .
Keep using EF6 if the data access code is stable and not likely to evolve or need new features. Port to EF Core if the data access code is evolving or if the app needs new features only available in EF Core. Porting to EF Core is also often done for performance.
NET Framework 4.8 | Free official downloads (microsoft.com). SQL Server 2014 and SQL Server 2012 use . Net Framework 3.5 SP1, which is supported till 2029, so this retirement doesn't impact them.
You can set SQL Server types assembly via SqlProviderServices.SqlServerTypesAssemblyName
static property.
So, put in startup code the following:
SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With