Linq и неподдерживаемые типы данных (География)

Статические методы связываются с классом. В Java интерфейс не является технически классом, это - тип, но не класс (следовательно, реализации ключевого слова, и интерфейсы не расширяют Объект). Поскольку интерфейсы не являются классами, у них не может быть статических методов, потому что нет никакого фактического класса для присоединения к.

можно назвать InterfaceName.class для получения Объекта класса, соответствующего интерфейсу, но класс Класса конкретно указывает, что это представляет классы и интерфейсы в JAVA-приложении. Однако сам интерфейс не рассматривают как класс, и следовательно Вы не можете присоединить статический метод.

5
задан Mr. Flibble 12 December 2009 в 05:11
поделиться

2 ответа

Cast the column to a varbinary(max), which Linq to SQL can handle. One way to avoid doing this in every query is just to add a computed column defined as CAST(GeographyColumn AS varbinary(max)).

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

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

You won't be able to query against the column this way; however, you can get what I would call halfway there using the Linq Dynamic Query Library. You won't have intellisense or some of the other Linq goodies, but it's still composable and therefore better than hand-crafting every query, and you can get strong-typed results.

Update: I found a slightly cleaner solution here. You can use the designer this way; just add the SqlGeography wrapper property to a partial class and use the STGeomFromWKB method with the SqlBytes class. That still won't give you inline query capabilities, though.

3
ответ дан 15 December 2019 в 01:03
поделиться

Похоже, вам придется вручную сопоставить / проанализировать его с вашим собственным типом POCO.

1
ответ дан 15 December 2019 в 01:03
поделиться
Другие вопросы по тегам:

Похожие вопросы: