c# - convert sql (row_number and DENSE_RANK) to linq -
i have below sql(ms-sql 2014) statement works .
how convert sql linq?
i'm reading now, putting out there in case can't it.
select originaldocumentnumber ,filterround , p2_reason , p2_finalgrade , rowno , s_index , t_index ( select * , rowno=row_number() on (partition originaldocumentnumber,filterround order p2_finalgrade desc) , s_index = row_number() over(partition filterround,originaldocumentnumber order p2_finalgrade), t_index = dense_rank() on (order p2_finalgrade) #tempda ) l l.p2_finalgrade in ('d','f') , l.rowno = 1 , l.originaldocumentnumber = '590200054' , l.p2_reason = 'test' , l.originaldocumentnumber+l.filterround not in (select originaldocumentnumber+filterround #tempda p2_finalgrade in ('a','b','c') )
update
list<string> validvalues = new list<string>() { "a", "b", "c" }; list<string> gradereject = new list<string>() { "d", "f" }; var tempdb = res.groupby(p => new {p.originaldocumentnumber, p.filterround}) .select(grp => grp.orderbydescending(g => g.p2_finalgrade).firstordefault()); var temp = res.where(r => validvalues.contains(r.p2_finalgrade)).select(r => r.originaldocumentnumber+r.filterround); fds = tempdb.where(r => gradereject.contains(r.p2_finalgrade) && !temp.contains(r.originaldocumentnumber + r.filterround)) .select(r => new dataallprocessdetailmodels() { filterround = r.filterround, originaldocumentnumber = r.originaldocumentnumber, documentnumber = r.documentnumber, landdescription = r.landdescription, dstatus = " " }).tolist();
thank much.
probably not relevant anymore whoever else crosses upon this:
answer more explanation how
dense_rank
:
answer specific question:
var result = data.groupby(item => new { item.originaldocumentnumber, item.filterround }) .orderby(@group => @group.first().p2_finalgrade) .asenumerable() .select((@group, groupindex) => new { items = @group.select((item, index) => new { item = item, index = ++index }), rank = ++groupindex }) .selectmany(v => v.items, (s, i) => new { data = i.item, rankingroup = i.index, denserank = s.rank }).tolist(); result.where(item => item.data.p2_finalgrade == "d" || item.data.p2_finalgrade == "f") .where(item => item.data.originaldocumentnumber == "590200054")....
Comments
Post a Comment