RowNumber using Linq

c# entity-framework linq sql

Question

How to use Linq to execute this sql query?

SELECT ROW_NUMBER() OVER(partition by T.SERRIA_NUMBER order by T.SERRIA_NUMBER),
       T.DATE_REG_END, 
       T.DATE_CHANGE
  FROM ZEM_LIC_UCH T
1
1
10/23/2014 4:22:44 AM

Accepted Answer

Here is a good example:

var query = db.ZEM_LIC_UCH
               .OrderBy(o => o.SERRIA_NUMBER)
               .GroupBy(g => g.SERRIA_NUMBER)
               .Select(s => new { s, Count = s.Count() })
               .SelectMany(sm => sm.s.Select(s => s)
                  .Zip(Enumerable.Range(1, sm.Count), (row, index) => 
                  new { 
                     rn = index, 
                     row.SERRIA_NUMBER, 
                     row.DATE_REG_END, 
                     row.DATE_CHANGE 
                  }))
               .ToList();
0
10/23/2014 6:28:48 AM

Popular Answer

try this:

var query=db.ZEM_LIC_UCH.OrderBy(t=>t.SERRIA_NUMBER)
                        .Select((t,i)=>new
                             {
                               row=i,
                               t.DATE_REG_END, 
                               t.DATE_CHANGE
                             });


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow