LINQ query with specified number of rows in a subquery problem
- by John
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?