Last week was quite simple and went without trouble , and just before I start enjoying my weekends – stuck in to in issue of getting ROW_NUMBER() (as we are doing in sandard SQL Query !
Finally come-up with sort and sweet code!
var items = context.ItemMasters.AsEnumerable()
.Select((u, index) => new ItemDetail
{ ItemId = u.ItemId,
ItemName = u.ItemName,
IsActive = (bool)u.IsActive,
Count = index + initialRow + 1
}).Skip(initialRow).Take(finalRow).ToList();
Please post comment if any other better solutions is possible for the same.
Thanks
Happy Coding !
Hi Vinay,
can you check with this statement. it will give rownumber like. 1,2,3,4….
ROW_NUMBER() over(order by itemid) as rownum
Thanks , that’s for sure works for SQL , but the code is for c# – LINQ
Thanks
Vinay
select * from(select ROW_NUMBER() over(order by id) n, * from [Product])t
where name=’jljljljlj’
can you make it to linq?
var productList = product.Select((r, i) => new { Row = r, Index = i })
.Where(x => x.Row.Name== ‘filter value’)
This would work for you.