i have this query:
var model2 = (from p in context.ViewChatPeoples
where ((IQueryable<int>)(from q in context.ConversationPeoples
where !q.Deleted && q.PersonId == info.LoginID
select new { q.ConversationId })).Contains(p.ConversationId)
select p.ConversationId).Distinct().ToList();
in LINQ / C#, however it seems to produce the following error:
Unable to cast the type 'System.Linq.IQueryable`1' to type 'System.Linq.IQueryable`1'. LINQ to Entities only supports casting Entity Data Model primitive types.
makes zero sense, i just want to run an WHERE IN, but seem to have hit this hurdle that makes no sense what so ever !!!
thanks
and as an update here is the final working code using the given solution:
var model2 = (from p in context.ViewChatPeoples
where ((from q in context.ConversationPeoples
where !q.Deleted && q.PersonId == info.LoginID
select q.ConversationId)).Contains(p.ConversationId)
select p.ConversationId).Distinct().ToList();
select new { q.ConversationId }creates an anonymously typed object with a property ConversationId. The code creates an IQueryable<[anonymous type]> instead of an IQueryable< int>.simply
select q.ConversationIdto get an IQueryable< int>.