[Solved] How to get rows with most recent nulls?


I’m not so familiar with Linq-To-Sql, so i’m not sure if it is supported, but try:

var query = db.TableName
    .Where(r1 => r1.Col2 == null 
            &&  r1.Col1 < db.TableName
                  .Where(r2 => r2.Col1 != null)
                  .Select(r2 => r2.Col1)
                  .OrderBy(col1 => col1)
                  .FirstOrDefault());

At least it should be the LINQ equivalent of this (working) sql-query: http://sqlfiddle.com/#!6/439be/6/0

solved How to get rows with most recent nulls?