Consider app that sets culture at the beginning of the request. It is must have, as we are handling many things that are culture dependent in the whole pipeline:
//some where at the beginning of the code
var noCulture = new CultureInfo("nb-NO");
CultureInfo.CurrentCulture = noCulture;
CultureInfo.CurrentUICulture = noCulture;
And then, somewhere on the bottom of code we have Entity Fremework (6.4.4) query:
var entities = (
from record in _dbConterxt.Records
//other joins etc, not relevant
select new RecordDto
{
//other props, not relevant
Status = Status ?? -1
}
).ToList();
The issue is that query generated uses U+2212 MINUS SIGN nb Norwegian Bokmål instead of
U+002D HYPHEN-MINUS en English. Please take a look at the query generated::
CASE WHEN ([Filter1].[Status] IS NULL) THEN -1 ELSE [Filter1].[Status] END AS [C9],
It throws:
An error occurred while executing the command definition. See the inner exception for details. Incorrect syntax near '−'. Incorrect syntax near the keyword 'AS'.
Is it possible to fix it somehow without:
- ignoring culture (like I said, it is needed to handle other cases / places properly)
- Rewriting query and getting rid of -1 (I know it is not the best approach but it is legacy code and we have other place like that).