views:

1301

answers:

3

I am using sql express 2008 and vs2008, writing in c#.

I have a db table with a Geography column in it, into which I need to put gps data I collected. When I tried creating an Entity-Framework mapping for this table, it just ignored the column with some warning about not being able to map such column types. I then looked at nHibernate.Spatial project, but it seems like it only translates the Geometry types, not the Geography. No luck there. I've been told I can use a view with casting the Geography to VarBinary, and then in the created entity class add another Property that deserializes the binary back into Geography. I guess that will work for reading the data from the db, but I also need to insert those rows into my db, and I can't add rows to the view. Is there some other trick I can use in order to easily read and write Geography data from my db, in my c# code?

+1  A: 

I don't know much about EF, but NHibernate allows you to extend it's type framework using IUserType. There's a bit about it on Ray Houston's Blog.

I've successfully used this to create a type for that uses XmlSerialization to an Xml field, based on Ayende's example

David Kemp
A: 

With NHibernate you ca use NHibernate.Spatial for your better mapping.

rarouš
as far as i can see NHiberate.Spatial only supports the geometry type yet
Joachim Kerschbaumer
A: 

At this time Entity Framework v1 does not support SQL UDT - 2008 Spacial type is UDT.

You can store your long/lat data using WKB (byte[]/varbinary).

As a side note i did not notice any support for UDT during the Microsoft MIX09 for the next version (1.5 CTP). Perhaps i missed something.

PulsarBlow