Quickhorn
Quickhorn

Reputation: 1181

Entity Framework: Get Inherited Types directly through Context

I have a TPT inheritance structure which allows me to query inherited objects in the context like this:

from test in Context.TestBase.OfType<DerivedType1>()
select test

Would it be possible for me to add these inherited types to the base context such that I can query like this:

from test in Context.DerivedType1
select test

Edit: To be clear, this is a database first structure.

Upvotes: 1

Views: 837

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

With DbContext and DbSet (EF 4.1+ and EF 5.0) yes. With ObjectContext and ObjectSet no unless you wrap your first query to a property but it will allow only querying but not adding, attaching or deleting. ObjectSet allows exposing only base types but DbSet allows exposing derived types directly as well.

Upvotes: 4

Related Questions