TSql to Linq translation
how can I translate this to Linq to SQL
I want to get all message responses (mr) but for each number in mr I only want messages that were received after 开发者_如何学JAVAthe 1st message (m) was sent
select mr.*
from
(select distinct PhoneNumber, MIN(SentDate) as MinSentDate
from Messages
groupby PhoneNumber)m,
join
MessageResponses mr on m.PhoneNumber = mr.PhoneNumber
where mr.ReceivedDate > m.MinSentDate
tks
It would look something like this
var query = from m in (from me in context.Messages
group me by me.PhoneNumber into mgr
select new
{
PhoneNumber = mgr.Key,
MinSentDate = mgr.Select(x => x.SentDate).Min()
}).Distinct()
join mr in context.MessageResponses
on m.PhoneNumber equals mr.PhoneNumber
where mr.ReceivedDate > m.MinSentDate
select mr;
精彩评论