I'm trying to do something that would seem very simple. I want to query for all types in a table per hierarchy, except for one type. This has to run as a single (pageable) database query.
To return a single type, I can call IQueryable<T>.OfType<T>()
. I don't see any way to pass a subset of types. As far as I know, the Discriminator cannot be exposed as a model property, so I cannot filter with any kind of Where(x => x.Discriminator != value)
call.
Someone suggested something like IQueryable<T>.Where(x => x is Type1 || x is Type2 || x is Type3)
, but I recall that kind of structure not working right. Someone also suggested using OfType
for each type, joined by Union
calls, but I think that would produce a poorer performing query than necessary when I'm trying to filter a single type from many types (e.g. exclude only 1 of 20 types, using 18 unions).
Is there a known way to perform such a query that I'm missing?