-
Couldn't load subscription status.
- Fork 53
Description
I have run into an issue similar to #60, however I get the above error when concatenating strings within my query.
Example
string a = "AAA";
string b = "BBB";
var selection = Entities.SOMETHING.Where( a => a.NAME == a + b );
This generates this SQL query as seen in the Exception
SELECT "Extent1"."ID", "Extent1"."NAME" FROM "SCHEMA"."SOMETHING" AS "Extent1" WHERE "Extent1"."NAME" = CASE WHEN ( CASE WHEN ($1 IS NULL) THEN (E'') ELSE ($1) END || CASE WHEN ($2 IS NULL) THEN (E'') ELSE ($2) END IS NULL) THEN (E'') ELSE ( CASE WHEN ($1 IS NULL) THEN (E'') ELSE ($1) END || CASE WHEN ($2 IS NULL) THEN (E'') ELSE ($2) END ) END
You can see that Npgsql is concatenating the strings within the SQL query, and this throws the 42P08: could not determine data type of parameter $1 Error.
If I put the result of the concatenation into a variable, there seem to be no issue.
string a = "AAA";
string b = "BBB";
string c = a + b;
var selection = Entities.SOMETHING.Where( a => a.NAME == c );
OK - Empty Result Set as expected
I also tried the following methods, manually casting the result, but they all seem to fail, unless I assign a value to a string variable first.
var dims1 = Entities.SOMETHING.Where(d => d.NAME == (a + b).ToString());
SELECT "Extent1"."ID", "Extent1"."NAME" FROM "SCHEMA"."SOMETHING" AS "Extent1"
WHERE "Extent1"."NAME" = CASE WHEN ( CASE WHEN ($1 IS NULL) THEN (E'') ELSE ($1) END || CASE WHEN ($2 IS NULL) THEN (E'') ELSE ($2) END IS NULL) THEN (E'') ELSE ( CASE WHEN ($1 IS NULL) THEN (E'') ELSE ($1) END || CASE WHEN ($2 IS NULL) THEN (E'') ELSE ($2) END ) END
could not determine data type of parameter $1
var dims2 = Entities.SOMETHING.Where(d => d.NAME == (string)(a + b));
SELECT "Extent1"."ID", "Extent1"."NAME" FROM "SCHEMA"."SOMETHING" AS "Extent1"
WHERE "Extent1"."NAME" = CASE WHEN ($1 IS NULL) THEN (E'') ELSE ($1) END || CASE WHEN ($2 IS NULL) THEN (E'') ELSE ($2) END
could not determine data type of parameter $1
var dims4 = Entities.SOMETHING.Where(d => d.NAME == string.Format("{0}_{1}", a, b));
LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)' method, and this method cannot be translated into a store expression.
Any suggestions to work around this without re-writing our LINQ queries?