Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I convert the following sql to LINQ

SQL
SELECT *
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY CPT4, CPT4MOD, ITEMCHARGE ORDER BY EFF_DATE DESC) AS RowNo
    , *
FROM #table
) AS T
WHERE T.RowNo = 1
Posted
Comments
PIEBALDconsult 22-Dec-14 9:30am    
Why? If it ain't broke why break it?
Arya440 22-Dec-14 9:34am    
Because I am not supposed to write SQL code in my application. I can only write LINQ, which I don't know well.
PIEBALDconsult 22-Dec-14 9:47am    
Who says?
Sinisa Hajnal 22-Dec-14 9:48am    
If you have to learn it, better convert it yourself. You'll get the knowledge faster then if you ask the question every time. Especially if that is for the whole application.
Sinisa Hajnal 22-Dec-14 9:50am    
You already asked the question about getting only max eff_date...didn't you?

1 solution

Let's say dataContainer is your container for data:
C#
List<yourdataclass> = dataContainer.OrderByDescending(x=>x.EFF_DATE).Select((x, i)=>new{
    Index = i+1,
    CPT4 = x.CPT4,
    CPT4MOD = x.CPT4MOD,
    ITEMCHARGE = x.ITEMCHARGE,
    EFF_DATE = x.EFF_DATE
    }).Where(x=>x.Index==1).ToList();</yourdataclass>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900