Open Ahmed-Abdelhameed opened 5 years ago
This is because SQL Server uses Bit (1 or 0) for boolean values. Therefore EntityFramework must use ORDER BY [field] ASC
in the SQL Statement.
However, JetEntity uses the "Yes/No" Access field for boolean values. Here, "Yes" is a value of -1, therefore they appear first.
A better workaround is context.Items.OrderBy(x => !x.IsActive)
.
See https://stackoverflow.com/questions/8827447/why-is-yes-a-value-of-1-in-ms-access-database for more details.
@jeremy-morren I do know that a "Yes/No" field in Access is represented as 0 or -1 value. However, since it's mapped by EF as a .NET Boolean type, it should be consistent with the Boolean type of the .NET Framework. EF is an ORM after all and works as a separation layer, therefore, it should (and it does) handle such conflicts behind the scenes (one example off the top of my head is that EF translates null
to DBNull
and vice-versa).
The following query:
context.Items.OrderBy(x => x.IsActive);
..returns items withIsActive == true
first then those withIsActive == false
(should be the opposite).Similarily, the following query:
context.Items.OrderByDescending(x => x.IsActive);
..returns items withIsActive == false
first then those withIsActive == true
(should be the other way around).This seems to be a bug in JetEntityFrameworkProvider because it works the right way with SQL Server and, of course, with any other collection. As a workaround, I'm currently using
context.Items.ToList().OrderBy...
.