Convert SQL Statement to LINQ VS2010

388 Views Asked by At

I would appreciate help in converting the following sql statement to linq:

select *
from (
    select 
        *,
        rn = row_number() over (partition by ClientId order by VisitId)
    from
        Visit
) activityWithRn
inner join vw_MasterView on  vw_MasterView.VisitId = activityWithRn.VisitId
where activityWithRn.rn =3

When I use Linqer (a wonderful program) I get the following error:

SQL cannot be converted to LINQ: Field [rn = row_number() over (partition by ClientId order by VisitId)] not found in the current Data Context.

Thanks in advance.

1

There are 1 best solutions below

4
On

I don't think there is any corresponding feature in LINQ for row_number() over, other than using Skip...Take:

var q = (from v in Visit
            join mv in vw_MasterView on v.VisitId equals mv.VisitId 
            orderby v.VisitId
            select v).Skip(2).Take(1);