How can I combine a LINQ query with an IQueryable<Guid>

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-05-26T23:56:05Z Indexed on 2010/05/27 0:01 UTC
Read the original article Hit count: 130

Filed under:
|

I have a LINQ query that uses 1 table + a large number of views. I'd like to be able to write something like this:

IQueryable<Guid> mostViewedWriters;

switch (datePicker)
{
    case DatePicker.Last12Hours:
        mostViewedWriters = from x in context.tempMostViewed12Hours
                            select x.GuidId;
        break;
    case DatePicker.Last24Hours:
        mostViewedWriters = from x in context.tempMostViewed12Hours
                            select x.GuidId;
        break;
    case DatePicker.Last36Hours:
        mostViewedWriters = from x in context.tempMostViewed12Hours
                            select x.GuidId;
        break;
}

var query = from x1 in context.Articles
join x2 in context.Authors on x1.AuthorId == x2.AuthorId
join x3 in mostViewedWriters on x2.AuthorId == x3.Id
select new { x2.AuthorName, x1.ArticleId, x1.ArticleTitle };

The above C# is pseudo-code written to protect the innocent (me). The gist of the question is this: I have a query that is related to the results of a view. That view, however, could be one of many different views. All the views return the same data type. I thought that I might be able to create an IQueryable that would contain the Ids that I need and use that query. Alas, that effort has stalled.

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql