25. september 2012 20:10 by admin in
Recently I deployed a site that internally used the new spatial CLR type DbGeography. When I tried to run I got the folowwing error :
Spatial types and functions are not available for this provider because the assembly 'Microsoft.SqlServer.Types' version 10 or higher could not be foundThis basically means that a dll is missing on the box. Since it is non-trivial to find this dll I'll blog about it. You have to install the SQLCltTypes package. If you install the wrong version of the package you might get a problem with SqlServerSpatial not being installed. The version that worken for me on Windows Server 2008 R2 x64 was here (below the x64 folder)
23. september 2012 08:21 by admin in
In a recent project we had to do some spatial search (finding nearest shops). With the new EntityFramework 5.0 in asp.net 4.5 this is finally possible. To get the nearest products (in a search) you write something like:
Now there can be some confusion about which type to use for location. There are two types to describe the 'location' of an object:
From MSDN:
DbGeography : Represents data in a geodetic (round earth) coordinate system.
DbGeometry : Provides a base class for objects that define geometric shapes.
Now here is a big difference. The first class being a point on earth and the second one a point (or shape). DbGeometry does not include anything about dimensions. This is clear when calculating the distance. When calculating distance for DbGeography the result is given in meters. For DbGeometry the result is still dimension less. A bit of code can say more than a thousand words...
So for real-world objects use DbGeography as location!