I’ve gone on at length before about inheritance in EF, specifically Table Per Type inheritance, and for the sake of this post, I’m going to assume you already know how to perform an outer join with LINQ. But what if you want to perform an outer join of a base class table to one (or more) subclass tables? I couldn’t think of a way to get it done, but a colleague presented a solution that seems blindingly obvious once demonstrated. In the following incantation, assume that Student is modeled as a subclass of Person:
The key is simply to realize that Persons represents the base table in the DB and Persons.OfType<Student>() represents the subclass table, and the rest falls into place.
Latest posts by Adam Anderson (see all)
- Kendo Undocumented: Binding to Parameterized Dependent Methods - September 14, 2014
- You can use LINQ’s ‘let’ keyword to tune the emitted SQL - August 28, 2014
- Kendo Exception During MVC Model Binding of DataSourceRequest - August 6, 2014
- Kendo Undocumented: Using data bindings in grid column templates - July 31, 2014
- HTTP GET array param to ASP.NET MVC with Kendo DataSource - July 30, 2014