I have a dataset that is built gradually in parts, and as each part is done, I'm associating the entries with their DENSE_RANK()
with the following code (source: implement dense rank with linq):
aQueryable.GroupBy(x => x)
.Where(g => g.Any())
.OrderBy(g => g.Key.SortOrder1)
.ThenBy(g => g.Key.SortOrder2)
.ThenBy(g => g.Key.SortOrder3)
.Select((g, i) =>
{
++i;
foreach (var x in g)
{
x.DenseRank = i;
}
return g;
}).Select(g => g.Key)
SQL equivalent: DENSE_RANK() OVER ( ORDER BY SortOrder1, SortOrder2, SortOrder3 )
However, the DenseRank that I'm computing here doesn't match the DENSE_RANK()
I get in SQL once the entire dataset is written. I suspect this is because I'm computing my DENSE_RANK()
on a subset of the full dataset.
Is there any way I can compute the same DENSE_RANK()
as SQL without waiting for my entire dataset to finish populating first?