Assume:
BaseEntity
ChildEntity : BaseEntity
The problem is getting the base entities with an efficient way. What I know that works is this type of query:
var results = context.BaseEntities.Where(entity => !(entity is ChildEntity) );
However this is very prone to breaking, as simply adding another extension to BaseEntity, like ChildEntityTwo : BaseEntity will break the query (query will include BaseEntity and ChildEntityTwo types.
Also, I havent had the chance to profile it yet but I suspect the query downloads all the entities and filters them in memory, but I could be wrong with this one.
Note that the solution context.BaseEntities.OfType<BaseEntities>() will actually include and download all the entities as well! It only works when you need an endpoint class, like ChildEntityTwo
ESQL offers
OFTYPE ONLYoperator for this purpose but that operator doesn’t have any equivalent in Linq. You can use this workaround to buildOFTYPE ONLYfor Linq.