Using Spatial Data With Sql 2012 and Windows Azure

By Ugo Lattanzi on Sept. 2nd , 2013 in .NET Azure | comments

Share On Google Share On Facebook Share On Twitter

In the last few weeks, I worked about some APIs using ASPNET Web Api and, for the data storage, Entity Framework and Sql Server; everything hosted on Azure.

Nothing sensational! make a rest call, read the data and return a json. The only new thing (for me) was the Spatial Data.

Thinking about this great post by Scott Hanselman, in this case I chose to be a Googler :D so, I started to learn Spatial Data with Entity Framework from this post by Rick Strahl.

Such as all posts by Rick, also this one is awesome. It explains very well all you need to start with Spatial Data and everything worked right at first try.

So, where is the reason of this post? The deploy. In my local environment, I was able to execute all Spatial Queries but, in the production environment, Iwas getting this strange message “The method or operation is not implemented.” In this line of code:

DbGeography.PointFromText(text, 4326);

Keep looking on Google I found the reason. DefaultSpatialServices in Entity Framework are using SqlGeography and SqlGeometry types as backing types. These are a part of Microsoft.SqlServer.Types.dll that is not included in the .NET Framework.

On my local installation it works because I've installed SQL Server and it register that assembly into the GAC (Global Assembly Cache) during the setup procedure. Fortunately Azure Web Site and Cloud Service don't have Sql Server installed so the assembly is missing.

The solution is to copy the assembly directly in your bin folder.

Now, where is the assembly located?

Not easy to find, anyway it’s here C:Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies

Stay Tuned!