Entity framework Code First: selecting data from a table with a discriminator

Sorry at first if my title is not clear, but it's hard for me to overlay it with a simple sentence in English :).

Let's say I have a site that manages people and super heroes, I have 2 classes:

 public class Person
    {      
        [Key]
        public int PersonId { get; set; }

        [MaxLength(100)]
        public string Name { get; set; }    
    }

  public class SuperHero:Person
    {    
        [MaxLength(100)]
        public string SuperHeroName { get; set; }
        public virtual ICollection<SuperPower> SuperPowers{ get; set; }
    }

In my database, I have the following:

Person 1: Id = 1 Name = "Alex Flimster" Discriminator = "Person"

Person 2: ID = 2 Name = "Bruce Wayne" discriminator = "SuperHero" SuperHeroName = "Batman"

I know if yes:

var test = from Context.Person select p;

I get everyone, hero or not.

If I want only a hero, I would do:

var test = from Context.Person.OfType<SuperHero>() select p;

My question is: how do I get only a person?

var test = from Context.Person.OfType<Person>() select p; 

It will return the same as in the first test.

Edit , . , 200 , 10 . , , , -. (, "VideoGame Hero", . , )

!

+5
1

from p in Context.Person
where !(p is SuperHero)
select p

Context.Person.Where(p => !(p is SuperHero))

UPDATE: SQL :

SELECT 
[Extent1].[Discriminator] AS [Discriminator], 
[Extent1].[PersonId] AS [PersonId], 
[Extent1].[Name] AS [Name], 
[Extent1].[SuperHeroName] AS [SuperHeroName]
FROM [dbo].[Person] AS [Extent1]
WHERE ([Extent1].[Discriminator] IN (N'SuperHero',N'Person')) 
      AND ([Extent1].[Discriminator] <> N'SuperHero')
+8

All Articles