i'm currently working on a project where i have to deal with sql server 2008 geography types. As big parts of the projects uses NHibernate as ORM i wonder how much work it will be to use/extend NHibernate.Spatial with this type (as far as i can see Nh Spatial only supports the geometry type yet). Btw. are there any other .net ORM's out there that support this sql type? thanks

- 88,164
- 40
- 182
- 265

- 9,695
- 7
- 49
- 84
-
I'm looking for the same thing. Have you discovered anything yet? Whats your current solution to nhibernate and sql server 2008 geography types? – Luke Smith Jan 28 '09 at 21:46
-
2i took Ricardo Stuven's SqlGeometry implementation from NHSpatial and extended it to work with SqlGeography type. there are still some minor bugs in it, but i can use IGeometry types and use geography as backend. I will send the code to the NHSP guys as soon as i get time to refactor/clean it up. – Joachim Kerschbaumer Jan 29 '09 at 10:07
-
Cool. I look forward to seeing/using it. – Luke Smith Jan 31 '09 at 12:59
-
I am looking forward to your addition to the NHSpatial project Joachim Kerschbaumer! – tobsen Feb 04 '09 at 19:01
-
@Joachim - did you manage to get this done? Thanks :-) – Perhentian Sep 10 '09 at 12:51
-
@Joachim - I would also like to see your implementation. I am struggling to get these types working with NHibernate. – Luke Foust Sep 28 '09 at 21:48
-
have you tried the code from the nhibernate.spatial subversion repository? i did a quick comparison and didn´t found great differences. the stuff ricardo stuven added to the repo should work imho. – Joachim Kerschbaumer Sep 29 '09 at 06:05
2 Answers
I don't know specifically about spatial, but you can always extend NHibernate to deal with your custom types which is quite straightforward (see NHibernate Custom Mapping Types) but the thing is that you have to explain how to deal with geography types to NHibernate (see namespace NHibernate.Type) teling NH how to convert the value back and forth to SQL.
It may not be the easiest thing in the world but can be done, many people may help you in nhusers and you will definitely learn a lot about the inner workings of an OR/M.

- 9,434
- 2
- 50
- 55
I asked the same thing in NHUsers back in January. NHSpatial has limited support for geography types. Check the thread at NHUsers below, you can 'sort of' use Geometry types for some Geography applications.
Also see the link that Ricardo posted on the group to Isaac Kunen's blog which gives an interesting example of the nearest neighbour problem in SQL.
So basically, the answer: No NHSpatial doesn't support Geography, but you can use Geometry types for some basic geography problems (e.g distance between two points). But you're better off running a Native SQL query to get the full power of SQL Server 2008's geography types.

- 26,181
- 22
- 92
- 123