Using a SQL Function in Entity Framework Select

大城市里の小女人 提交于 2020-01-01 18:30:13

问题


I am using the Devart EF-4 provider for PostgreSQL.

In one of my db tables, I have a column called the_geom which is a PostGis Geometry type column holding a polygon. Long story short, PostGis uses its own binary format to store geometry values, so for it to be usable in my application i need to convert it to Well-Known-Binary (WKB) which is a standardized binary representation of geometry. This can be achieved quite easy in standard SQL by selecting in with

select asbinary(the_geom) from mytable

The final question is this: How do I, in Entity Framework, specify to use the asbinary() function to select the_geom column?


回答1:


There is a bunch of Sql Server functions that you can use in Linq querys in SqlFunctions class in System.Data.Objects.SqlClient namespace.

Look for sth like that in your Linq Provider library for Postgre, and if you can't find add a computed column with the value of asbinary(the_geom) and map that column in EF.

You may even could write sth like that if you look at the decompiled code,

public static class SqlFunctions
{
    // Methods
    [EdmFunction("SqlServer", "STR")]
    public static string StringConvert(double? number)
    {
    }
}


来源:https://stackoverflow.com/questions/4613111/using-a-sql-function-in-entity-framework-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!