Entity framework Code First: select data from table with discriminator

后端 未结 1 1642
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 09:02

First sorry if my title is not clear, but I do have hard time putting it as simple sentence in English :).

Let\'s say I have a website that manages, people and super

相关标签:
1条回答
  • 2021-01-18 09:36

    Try this

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

    Or fluent one

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

    UPDATE: SQL will look like:

    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')
    
    0 讨论(0)
提交回复
热议问题