in .NET Framework

OrderBy making null records come last Entity Framework and Linq

Ever want to sort your result set but make sure the records with a null sorting column appear last?
See the example below

1
2
3
4
5
6
7
8
9
10
var results = (from x in EntityObjectContext.MyTable
              select x
              into grp
              select new
              {
            mydata = grp,
            myid = grp.id,
            mysortingentity = grp.mysortingentity
              }
             ).OrderBy(x => sortingcolumn == null).ThenBy(x => x.mysortingentity.Name).ThenBy(x => x.myid);

Watch this space, this can easily be transformed into a Extension Method. Check out this link http://tahirhassan.blogspot.com/2010/06/linq-to-sql-order-by-nulls-last.html, this Extension method works for LinqToSQL.