Bug #51475 Entity Framework - OrderBy Statement SQL Translation Failure
Submitted: 24 Feb 2010 20:45 Modified: 25 Mar 2010 8:21
Reporter: Nathan Taylor Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.2.2 OS:Any
Assigned to: Assigned Account CPU Architecture:Any
Tags: entity-framework, orderby

[24 Feb 2010 20:45] Nathan Taylor
Description:
I currently have a table structure defined in one of my applications where there is a column for a given table called "Order" which is a nullable integer used to sort the results returned within the application. The intended behavior is to have all non-null values appear first in the correct order, followed sequentially by all null values. To do this the following statement was used:

var list = EntityCollection.OrderBy(e => e.Order ?? int.Max);

However, running the above statement produces the following exception:

ArgumentException: A valid ResultType could not be inferred from the ResultTypes of the specified 'Then' expressions.

I also attempted to do:

var list = EntityCollection.OrderBy(e => e.Order.HasValue ? e.Order.Value : int.Max);

Which compiled, but did not affect the default ordering of the collection in any way. Likewise with the same expression applied to OrderByDescending().

The only way I was able to make this work was by executing the query with .ToList() and then executing the OrderBy at that point. Naturally, this is not especially desirable.

How to repeat:
Create a table entity with a nullable value.
Attempt to sort the table data by that nullable value using a LINQ to Entities Expression: EntityCollection.OrderBy(e => e.Order ?? int.Max);
[25 Feb 2010 8:21] Tonci Grgin
Hi Nathan and thanks for your report.

It would be very very nice to attach DDL/DML statements used, a part of general query log showing what actually got to MySQL server and a sample project file showing the problem between what you expected and what you actually got.
I don't think me guessing what would all that be is a viable choice...
[26 Mar 2010 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".