Curious problem, not sure how to do this in linq. Part of the problem might be that I’m trying to do this all at once.
I have a phase table
[id, name, [order]]
{{1, 'phase 2', 2}, {2, 'phase 1', 1}
I’d like to get a percentage of progress through all the phases for a given phaseid.
I know of a way to do this with sql.
SELECT (SELECT a.row
FROM [phase] p
INNER JOIN (SELECT Row_number()
OVER(
ORDER BY [order]) row,
id
FROM [phase]) p2
ON p2.id = p.id
WHERE p.id = @phaseid) / CONVERT(FLOAT, Count(*))
FROM [phase]
Is there a way to do this in linq? All my attempts seem to fail
Try the following:
It first queries the IDs of all Phases from the database, already correctly ordered. In memory, it then generates the row number and filters out the phase with the requested ID.
Based on the index and the total count of phases, the percentage is then calculated.