I am trying to implement the equivalent of T-SQL code where in (select ...) in LINQ.
This is what I have now:
int contactID = GetContactID(); IEnumerable<string> threadList = (from s in pdc.Messages where s.ContactID == contactID group 1 by new { s.ThreadID } into d select new { ThreadID = d.Key.ThreadID}).ToList<string>(); var result = from s in pdc.Messages where threadList.Contains(s.ThreadID) group new { s } by new { s.ThreadID } into d let maxMsgID = d.Where(x => xsContactID != contactID).Max(x => xsMessageID) select new { LastMessage = d.Where(x => xsMessageID == maxMsgID).SingleOrDefault().s };
However, my code will not compile due to this error for ToList() :
cannot convert from System.Linq.IQueryable<AnonymousType#1> 'to System.Collections.Generic.IEnumerable<string>
Are there any suggestions on how to implement this? Or any suggestions to simplify this code?
source share