title: EF Linq to entities query generating UNION for TPC CTP5 code-first entity
body: <p>I have the following entities:</p>
  
  <pre><code>public class User
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  
  public class HappyUser : User
  {
      public bool IsHappy { get; set; }
  }
  </code></pre>
  
  <p>I am configuring the entities using Table Per Concrete Type (TPC) in order to generate a User table and a HappyUser table. I want the HappyUser table to include the properties of the User class, and I don't want any relationship between the two tables. </p>
  
  <p>I configure the entities as follows:</p>
  
  <pre><code>public class UserTest : DbContext
  {
      public DbSet&lt;User&gt; Users { get; set; }
      public DbSet&lt;HappyUser&gt; HappyUsers { get; set; }
  
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;HappyUser&gt;().Map(m =&gt;
          {
              m.MapInheritedProperties();
              m.ToTable("HappyUser");
          });
      }
  }
  </code></pre>
  
  <p>The tables are generated correctly, but when I query the tables, EF generates a UNION on the User and HappyUser table. The query is as follows:</p>
  
  <pre><code>        UserTest db = new UserTest();
  
          var users = from u in db.Users
                      select u;
  
          var happyUsers = from u in db.Users.OfType&lt;HappyUser&gt;()
                           select u;
  </code></pre>
  
  <p>The SQL for the Users generates a UNION. This is not what I expect or want. I'd like to simply retrieve the rows from the Users table.</p>
  
  <pre><code>SELECT 
  CASE WHEN ([UnionAll1].[C2] = 1) THEN '0X' ELSE '0X0X' END AS [C1], 
  [UnionAll1].[Id] AS [C2], 
  [UnionAll1].[Name] AS [C3], 
  CASE WHEN ([UnionAll1].[C2] = 1) THEN CAST(NULL AS bit) ELSE [UnionAll1].[C1] END AS [C4]
  FROM  (SELECT 
   [Extent1].[Id] AS [Id], 
   [Extent1].[Name] AS [Name], 
   CAST(NULL AS bit) AS [C1], 
   cast(1 as bit) AS [C2]
   FROM [dbo].[User] AS [Extent1]
  UNION ALL
   SELECT 
   [Extent2].[Id] AS [Id], 
   [Extent2].[Name] AS [Name], 
   [Extent2].[IsHappy] AS [IsHappy], 
   cast(0 as bit) AS [C1]
   FROM [dbo].[HappyUser] AS [Extent2]) AS [UnionAll1]
  </code></pre>
  
  <p>The SQL for the HappyUsers works as expected. </p>
  
  <pre><code>SELECT 
  '0X0X' AS [C1], 
  [Extent1].[Id] AS [Id], 
  [Extent1].[Name] AS [Name], 
  [Extent1].[IsHappy] AS [IsHappy]
  FROM [dbo].[HappyUser] AS [Extent1]
  </code></pre>
  
  <p>Any ideas what I am doing wrong? Or is this a defect in EF? </p>