I have two tables, subscriptions and topics. Each subscription is related to a specific TopicID (PK for topics table). The first query works fine and retrieves the topicID's of all videos that were uploaded today.
The problem occurs when I try and then use the results of query1 as a where-in clause for query 2. I keep receiving object reference not set to instance of an object.
Query 1
IQueryable<int> topics = (from t in dataLayer.Videos
where SqlMethods.DateDiffDay(t.DateCreated, DateTime.Today) == 0
select t.TopicID).Distinct();
Query 2 (fails)
IQueryable<Subscription> subs = from s in dataLayer.Subscriptions
where topics.Contains(s.TopicID)
select s;
The Linq query generated when it fails is {Table(Subscription).Where(s => value(EmailSubscribers+<>c__DisplayClass0).topics.Contains(s.TopicID))}
Any insight into this would be appreciated. I have looked at some samples around the net and they all seem to be identical to mine.