Anders Jakobsen
Anders Jakobsen

Reputation: 1085

Using a SQL Function in Entity Framework Select

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?

Upvotes: 2

Views: 1492

Answers (1)

Jahan Zinedine
Jahan Zinedine

Reputation: 14874

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)
    {
    }
}

Upvotes: 5

Related Questions