Sql Spatial Type, Code First migration and Azure DB

122 Views Asked by At

I'm on a project with an azure DB and Entity Code First. I'd like to add Spatial Type (DbGeography) in my project.

I installed the package in my in the model project with Install-Package Microsoft.SqlServer.Types then tried Add-Migration AddDbGeography but I keep getting this Error Message

Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found .

any help is welcome :)

(I have tried to uninstall/install latest version of CLR Types for Microsoft® SQL Server but nothing work)

2

There are 2 best solutions below

0
On

Let's start with basic checks. Please check if you have both x86 and x64 version of the Microsoft.SqlServer.Types assembly installed. It might be that wrong one is installed, or that both of them are installed and one of them is older than expected.

0
On

I have read that downgrading your Microsoft.SqlServer.Types nuget package to V11 may assist with this issue. I didn't want to do this, however, so instead, in a fit of "monkey-see-monkey-do" programming I put the following code into the Configuration method of the Configuration.cs file

    public Configuration()
    {
        AutomaticMigrationsEnabled = false;

        //Adding this fixes the below error message...
        //Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be found. 
        SqlProviderServices.SqlServerTypesAssemblyName = typeof(SqlGeography).Assembly.FullName;
    }

This removed the error message and allowed me to generate a migration without having to downgrade the package. Still to see how that goes, but it's a quick fix, that I cribbed from this thread on github.