1

My sql code is below, I'm trying to Convert it to linq. I'm getting stuck on how to do row_number() over (partition part. If i can get some guidance or assistance please and thank you.

with summary AS
(select * from
    (select p.loan_guid,
    p.TransactionDate,
    p.balanceoutstanding,
    row_number() over (partition by p.loan_guid
    order By linenumber desc) as rk
    from (select * from transactions1
         where transactiondate <= @EndDate )as p ) 
         as S where S.rk = 1)
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user2785177
  • 69
  • 1
  • 10
  • possible duplicate of [Row\_number over (Partition by xxx) in Linq?](http://stackoverflow.com/questions/9980568/row-number-over-partition-by-xxx-in-linq) – Ehm Feb 05 '15 at 13:24

1 Answers1

0

I am having trouble finding a definitive answer, but my guess would be that Linq does not support analytic/window functions. If you are using Entity Framework, then you can always designate a type, execute the raw query and EF will map and track the results for you. Here is an example:

using(var ctx = new MyContext){
    var myObjects = ctx.Products.SqlQuery("<Your Query>").ToList();
}

the result will be a list of objects of type Product.

This creates a dependency in your application on a SQL database, but I would prefer to have a clean SQL query that I can refactor later if necessary, Then an enormous Linq query in your code.

mmilleruva
  • 2,110
  • 18
  • 20