Here is the scenario -
We have an application that supports posting to multiple social sites (Facebook, Twitter, G+, etc).
We used TPH to structure this, all in one Posts
table, with a discriminator column. Each of these "Social" posts derives from a common base class called, appropriately, SocialPost
.
It was that we would just say context.SocialPosts
and it would grab everything with a discriminator for FacebookPost
, TwitterPost
, and GooglePost
.
Now we have a need to be able to grab a mix-and-match of the types. Based on a setting, we want to pull back all, for example, Facebook and Google Posts to process, while leaving Twitter untouched.
Is there a sane way to do that in one query?
The following code
context.SocialPosts.Where(x=>x is FacebookPost || x is GooglePost)
will produce SQL like the following
SELECT * FROM Posts WHERE Discriminator IN ('FacebookPost', 'TwitterPost', 'GooglePost') AND Discriminator IN ('FacebookPost','GooglePost')
which is clearly not what I want. I'm not sure if having the double filter on the Discriminator matters, per se, but it's definitely weird SQL to be using.
So, is there a sane way to grab multiple discriminator types with one query, or would it be better to grab all SocialPosts
and then filter out the ones I don't want on the application end.