LINQ query with specified number of rows in a subquery problem

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-28T21:22:22Z Indexed on 2010/04/28 21:27 UTC
Read the original article Hit count: 178

Filed under:
|

I'm trying to write the following query in LINQ, but can't seem to get it correct.

select p.*
from Person p
inner join PersoniPhones i ON p.PersonID = i.PersonID
where p.PersonID in
(
    SELECT PersonID
    FROM
        (
        SELECT Top 10 PersonID, iPhoneID
        FROM iPhone
        ORDER BY LastPlayedDate DESC
        ) as t
)

I've tried the following, but it doesn't return correctly

        var tenIPhones = from i in context.PersonIPhones
                         .OrderByDescending(i => i.LastPlayedDate)
                         .Take(minNumQuestions)
                         select new { i.PersonID, i.IPHoneID};
        var people = from p in context.Person
                 join t in tenIPhones on p.PersonID equals t.PersonID
                 select p;

Any ideas?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about subquery