When using traditional Entity Framework and querying with ESQL, you can use OFTYPE with ONLY to only return base types.
See: http://msdn.microsoft.com/en-us/library/bb399295.aspx
In Entity Framework Code First, I have inheritance set up where B is a subtype of A. Performing MyContext.Set<A>().OfType<A>() still returns elements of type B. Ideally, I would like to call MyContext.Set<A>().OfOnlyType<A>() and it would translate the same way as when using ESQL’s OFTYPE ONLY.
I also found I can use the is operator in a where statement, but again, that will return both A and B entities.
How can I write a linq expression that will filter to only elements of type A?
There is no way to get only
Ainstances directly (equivalent toONLY) in Linq-to-entities unless you somehow exclude derived instances from the result set. For example: