16

I have a form from which the user will be able to enter the latitude and longitude of a certain point on the map. The data will be input as string values. I did some research and found out from various sources that the Entity Framework doesn't support geography data types.

  • How can I parse and/or save the string data to a geography column in a database?
  • How can I access it and reparse it as string once it is stored?

Thanks in advance!

Filip Filipovic
  • 354
  • 3
  • 7
  • 20

1 Answers1

20

In fact Entity Framework 5 components that are shipped with .NET Framework 4.5 do support spatial types. Take a look at this walkthrough.

EDIT With EF6 you can use spatial types on both .NET Framework 4 and .NET Framework 4.5

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • Great article. Thank you for recommending this. – Filip Filipovic May 18 '12 at 20:14
  • 2
    So, the problem I'm seeing is that I keep my POCOS as clean as possible leaving out all references / dependencies to entity framework and the persistence store as possible, then have a set or Repository classes which know about the persistence store. I also stay away from DataAnnotation attributes using fluent configuration. As soon as you put DbGeography you need 'using System.Data.Entity' which breaks the persistence agnostic approach, at least for the "Plain" Old C# Object. – Stephen York Dec 10 '15 at 20:40
  • .NET does not have a native spatial type so how else would you go about this? You obviously could hack a little bit by not using EF spatial types but `byte[]` for spatial properties in your entities but then you would still need to somehow translate it to and from the byte[] to make it usable. – Pawel Dec 10 '15 at 22:14