Linq & unsupported data types (geography)

So, Linq does not support the data type Geography, which throws the main wrench to work in a beautiful drag and drop table onto the Linq model development model.

Is there a way to extend Linq to work with a geography type? Or will I need to create a whole new datalayer and query set when I need to use geography columns?

I have been stuck with this for several days and cannot decide if this is possible.

+5
source share
2 answers

Insert a column into varbinary (max) that Linq to SQL can handle. One way to avoid this in every query is to simply add a calculated column defined as CAST(GeographyColumn AS varbinary(max)).

Once you have the data byte[], you can write a short utility method to convert it to an actual class Microsoft.SqlServer.Types.SqlGeographyusing the MemoryStreamand methods IBinarySerialize. Read/ Write.

As far as I know, this is the only working solution if you need to work with any type of CLR, including geography, geometry, hierarchy and any custom types. Linq does not "support" any of them. It's a bit of a pain to write all the boilerplate code, but you can simplify it with a few extension methods.

; , , Linq Dynamic Query Library. intellisense Linq, - , , , , .

: . ; SqlGeography STGeomFromWKB SqlBytes. .

+3

, / POCO.

+1

All Articles