score:3
Accepted answer
Method Syntax
var query = enumerable.OrderBy(x => x.order == null ? 1 : 0).ThenBy(x => x.order);
Query Syntax
var query = from x in enumerable
orderby (x.order == null ? 1 : 0), x.order
select x;
score:0
Assuming order is a nullable value (not an object), you should be able to use this:
orderby null == order ? 1 : 0, order
If it is an object, you could try
orderby null == order ? 1 : 0, order.PropertyName
Source: stackoverflow.com
Related Articles
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- How can I translate this SQL Order By statement to LINQ-To-Object?
- linq how would i order this statement
- C# SQL Statement transformed TO LINQ how can i translate this statement to a working linq
- Translate this VB.NET LINQ statement to C#, having trouble
- How do I translate this specifik SQL statement to LINQ
- How do I translate this Sql Statement to Linq
- Translate LINQ to sql statement
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Why won't this LINQ join statement work?
- Does this LINQ code perform multiple lookups on the original data?
- How do I write this in Ruby/Python? Or, can you translate my LINQ to Ruby/Python?
- How can I use LINQ to project this parent and children object model into a flat, single object?
- LINQ Source Code Available
- How does this linq code that splits a sequence work?
- multiple orderby in this linq code
- How can I combine this code into one or two LINQ queries?
- Linq with where clause in many-to-many EF Code First object
- Order of execution of LINQ methods returning same results but different SQL in this code. What exactly is going on inside?
- How can I further simplify this piece of LINQ code
- Is there a bug in this code from 101 LINQ Samples on MSDN? (Update: Fixed)
- How to render this map-reduce javascript code to an equivalent LINQ Select-Aggregate?
- Make an Anonymous object for Linq Select statement
- LINQ approach to this code
- Resharper reworked a for loop. Is this LINQ statement doing too much in one line?
- Order a parent object by a child's property in LINQ
- LINQ - How can I give a child object in a select statement a reference to its parent?
- How to translate this SQL query to a LINQ query in EF Core?
- I want to convert this foreach loop to a LINQ statement
- How can I speed up this linq query on a List<> with search criteria on 3 attributes in the list object
- How to optimize linq query for speed?
- Linq Expression to create instance of Type with optional args?
- How can i call from another method a linq?
- LINQ: Average of a Sub IEnumerable
- LINQ query to XML file to get child tags
- Replacing the parameter name in the Body of an Expression
- LinQ Grouping records with null values
- How can I do a compare with space omitted in a LINQ where?
- LINQ IQueryable Check if Empty without Enumerating
- How to replace values smaller than zero with zero in a collection using LINQ
- cannot implicitly convert type in LINQ
- Linq to SQL: Aggregating over ||
- Compare two Lists using Linq for partial matches
- linq multiple columns; getting weird results
- Create dynamic LINQ expression for Select with FirstOrDefault inside
- LINQ Room id where user exists
- LINQ query to select top five
- LINQ to SQL: Stored Procedure Results
- Convert foreach to LINQ with 'is' operator
- Linq include only max row