EF generates query with not supported minus sign in MS SQL (f.e. norvegian culture)

42 Views Asked by At

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:

  1. ignoring culture (like I said, it is needed to handle other cases / places properly)
  2. 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).
0

There are 0 best solutions below