ToString() in LINQ expression

ToString() in LINQ expression

Postby xms » Mon 26 May 2014 06:05

Trying to create an expression to query against multiple combined fields that together create a unique ID. There's a prefix, id number, suffix and version number - the first 3 fields being strings and version number being a integer.

So querying against X1000T would query against the combined prefix X + id number 1000 + suffix T for version 0, using an expression that looks like this:

query = query.Where(n => (((n.prefix ?? "") + n.idnumber + (n.suffix ?? "") + (n.version == 0 ? n.ToString() : n.version.ToString()) ) == combined_id));

This generates an exception on the Tostring method:
LINQ to Entities does not recognize the method 'System.String ToString()' methodtranslated store expression


EF has a SqlFunctions.StringConvert method but this only works with SQL Server, need something similar for Postgres.

Is there an equivalent? Could one generate an extension to take care of this - and are there any examples illustrating something like this?

Any help is appreciated.

Regards,
xms
 
Posts: 2
Joined: Mon 26 May 2014 05:46

Re: ToString() in LINQ expression

Postby Shalex » Tue 27 May 2014 13:44

Please try using PgSqlFunctions.ToChar() instead of SqlFunctions.ToString().

The functions from the System.Data.Objects.SqlClient.SqlFunctions class are used only by .NET Framework Data Provider for SQL Server (System.Data.SqlClient).
dotConnect for PostgreSQL (Devart.Data.PostgreSql) works with the functions from Devart.Data.PostgreSql.Entity.PgSqlFunctions. There is no way to use SqlFunctions with dotConnect for PostgreSQL because the SqlFunctions class is specific to SQL Server only.
General functions for all EF-providers are available in the System.Data.Objects.EntityFunctions class.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: ToString() in LINQ expression

Postby xms » Thu 05 Jun 2014 05:57

Thanks for your reply.

I can't find any examples related to PgSqlFunctions - in documentation, downloads sections or forums.

Are there any?

Regards,
xms
 
Posts: 2
Joined: Mon 26 May 2014 05:46

Re: ToString() in LINQ expression

Postby Shalex » Fri 06 Jun 2014 07:36

We are working on the corresponding section of the dotConnect for PostgreSQL documentation. We will notify you when it is implemented. Currently, if you have any particular questions about PgSqlFunctions, please contact us.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for PostgreSQL