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,
ToString() in LINQ expression
Re: ToString() in LINQ expression
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.
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.
Re: ToString() in LINQ expression
Thanks for your reply.
I can't find any examples related to PgSqlFunctions - in documentation, downloads sections or forums.
Are there any?
Regards,
I can't find any examples related to PgSqlFunctions - in documentation, downloads sections or forums.
Are there any?
Regards,
Re: ToString() in LINQ expression
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.