It looks like you're taking the first record in each key grouping where rev
is 0 or equals the revnum
parameter. You can do that in Linq with:
var query = db.records
.OrderBy(r => r.rev == revNum ? 0 : 1)
.Where(r => rev == 0 || rev == revNum)
.GroupBy(r => r.key)
.Select(g => g.First());
if records contains more that the three fields in the query then just add
.Select(r => new {r.key, r.rev, r.IsCurrent})