11,578 questions
Try something like this:
var query =
Beatles
.GroupBy( b => b.inst )
.SelectMany( g => g.OrderBy( b => b.id ).Select( ( b, i ) => new { b.inst, b.id, rn = i + 1 } ) );
var results = query.ToList( );
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
See sample sql
SELECT
*
,Row_Number() OVER (PARTITION BY inst ORDER BY id) AS rn
FROM Beatles
How to write same kind of query by LINQ?
Please suggest.
Try something like this:
var query =
Beatles
.GroupBy( b => b.inst )
.SelectMany( g => g.OrderBy( b => b.id ).Select( ( b, i ) => new { b.inst, b.id, rn = i + 1 } ) );
var results = query.ToList( );