How to read / write geography data using C#, Entity Framework and SQL Server 2008?

Filip Filipović picture Filip Filipović · May 18, 2012 · Viewed 21.6k times · Source

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!

Answer

Pawel picture Pawel · May 18, 2012

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