Maybe I\'m missing something. I have a sql server column of the \"Geography\" datatype.
I want to use the DbGeography type in my c# code. Any way to cast or convert
When the performance is of any importance, the well-known binary should be used instead of the well-known text:
var newGeography = DbGeography.FromBinary(theGeography.STAsBinary().Value);
There is an overload using a SRID, if that is important. In my simple test with a 1,000 reasonably complicated polygons the binary-based approach is 4 times faster than the text-based one:
* Binary-based conversion
Run 1: 1948
Run 2: 1944
Run 3: 1959
Run 4: 1979
Run 5: 1988
Average: 1963.6
* Text-based conversion
Run 1: 8527
Run 2: 8553
Run 3: 8596
Run 4: 8535
Run 5: 8496
Average: 8541.4