Use LINQ to move item to top of list

What do you want to order by, other than the known top item? If you don’t care, you can do this:

var query = allCountries.OrderBy(x => x.id != 592).ToList();

Basically, “false” comes before “true”…

Admittedly I don’t know what this does in LINQ to SQL etc. You may need to stop it from doing the ordering in the database:

var query = allCountries.AsEnumerable()
                        .OrderBy(x => x.id != 592)
                        .ToList();

Leave a Comment