I have an example where I want a IQueryable to convert to an IEnumerable (in order to use a multi-statement lambda), and then I immediately want to convert back to a IQueryable to use an extension method that requires IQueryable.
This is within a LINQ query if that matters?
My question is whether this can be time or space intensive? Or, more plainly, should I avoid it for any reason?
Here is the use case of this scenario:
var messageTimelines = ctx.UserMessageTimelines.AsEnumerable()
.Where(w =>
{
var intersectCount = w.MessageTimelineParticipants.Intersect(timelineParticipants).Count();
return ((intersectCount == w.MessageTimelineParticipants.Count()) && (intersectCount == timelineParticipants.Count()))
? true : false;
}).AsQueryable().ProjectTo<MessageTimeline>(mapper.ConfigurationProvider);
As you can see I started off as a IQueryable and converted to 'AsEnumerable()' in order to utilize a multi-statement lambda. I then converted back to 'AsQueryable()' in order to use an AutoMapper extension method called 'ProjectTo', which requires 'IQueryable'.
To Note:
- This post almost answers my question, but doesn't speak of converting back to the sub-type IQueryable: does converting IQueryable to IEnumerable execute the query again?