Search code examples
c#entity-frameworkef-code-firstentity-framework-6tph

How to retrieve rows from a specific discriminator in EF 6.1.3?


I'm using TPH approach in my code-first model, the base class is of type WItem and the derived is BItem, I want to retrieve all the WItems rows only, so I made this

return View(db.WItems.OfType<WItem>().ToList());

but I still get all the rows WHERE [Extent1].[Discriminator] IN (N'BItem',N'WItem')}?


Solution

  • A fellow from Quora suggested this:

    db.WItems.Where(s => !(s is BItem));
    

    It works as I hoped.