Reputation: 2821
I´m doing the Walkthrough: Mapping Inheritance - Table-per-Hierarchy (Entity Data Model Tools).
This is the model:
The entities Instructor and Student are derived types with the BaseType Person.
The problem is: How can I query the Instructor and Student entities directly in LINQ if they are not visible in ObjectContext?
I was expecting to do somenthig like this:
var result = from student in ctx.Students select student;
The derived entities seems to exist only as entities (EntityObject) and not as ObjectSet.
Thanks!
Upvotes: 2
Views: 626
Reputation: 74540
You should have a People
property on the ObjectContext
class that is generated for you. From there, you can get all the base types:
var allPeople = ctx.People;
Or, if you want a specific derived type, you can use the OfType
extension method on IQueryable<T>
, like so:
var students = allPeople.OfType<Student>();
var instructors = allPeople.OfType<Instructor>();
Upvotes: 1