title: Not updating discriminator when property type changes
body: <p>I've got an entity that has a property that's an abstract type. This creates a one-to-one relationship that uses table-per-hierarchy inheritance. Everything seems like it's working correctly.</p>
  
  <p>I can create an Item and set the <code>Base</code> property to <code>ConcreteOne</code>; everything saves correctly. However, when I try to update <code>Base</code> to <code>ConcreteTwo</code>, EF updates the <code>Base</code> record in the database with the new user value, it doesn't update the discriminator for the type. So the extra data for <code>ConcreteTwo</code> gets persisted, but the discriminator still says <code>ConcreteOne</code>.</p>
  
  <p>The following is a simple example that exposes the problem</p>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              App_Start.EntityFrameworkProfilerBootstrapper.PreStart();
  
              Database.SetInitializer(new DropCreateDatabaseAlways&lt;DataContext&gt;());
  
              // Create our item with ConcreteOne for Base
              using (var context = new DataContext())
              {
                  var item = new Item
                      {
                          Base = new ConcreteOne { Name = "Item", Data = 3 }
                      };
                  context.Items.Add(item);
                  context.SaveChanges();
              }
  
              // Update Base with a new ConcreteTwo
              using (var context = new DataContext())
              {
                  var item = context.Items.FirstOrDefault();
  
                  var newBase = new ConcreteTwo()
                      {
                          Item = item,  
                          Name = "Item 3", 
                          User = new User { Name = "Foo" }
                      };
  
                  // If I don't set this to null, EF tries to create a new record in the DB which causes a PK exception
                  item.Base.Item = null;  
                  item.Base = newBase;
  
                  // EF doesn't save the discriminator, but DOES save the User reference
                  context.SaveChanges();
              }
  
              // Retrieve the item -- EF thinks Base is still ConcreteOne
              using (var context = new DataContext())
              {
                  var item = context.Items.FirstOrDefault();
                  Console.WriteLine("{0}: {1}", item.Name, item.Base.Name);
              }
  
              Console.WriteLine("Done.");
              Console.ReadLine();
          }
      }
  
      public class DataContext : DbContext
      {
          public DbSet&lt;Item&gt; Items { get; set; }
      }
  
      public class User
      {
          public int Id { get; set; }
          public string Name { get; set; }
      }
  
      public class Item
      {
          public int Id { get; set; }
          public string Name { get; set; }
          public virtual Base Base { get; set; }
      }
  
      public abstract class Base
      {
          public int Id { get; set; }
          public string Name { get; set; }
  
          [Required]
          public virtual Item Item { get; set; }
      }
  
      public class ConcreteOne : Base
      {
          public int Data { get; set; }
      }
  
      public class ConcreteTwo : Base
      {
          public virtual User User { get; set; }
      }
  }
  </code></pre>
  
  <p>When the changes are saved, EF generates the following SQL:</p>
  
  <pre><code>update [dbo].[Bases]
  set    [Name] = 'Item 3' /* @0 */,
         [User_Id] = 1 /* @1 */
  where  (([Id] = 1 /* @2 */)
          and [User_Id] is null)
  </code></pre>
  
  <p>So it's almost correct, but I'd expect to see <code>[Discriminator] = 'ConcreteTwo'</code> in the update statement. Are my expectations unfounded or am I doing something wrong?</p>
  
  <p>As a test, I tried using table-per-type and the the entry was removed from the <code>ConcreteOne</code> table and added to the <code>ConcreteTwo</code> table as I would expect. So it works, but my real application has at least seven sub-types and the SQL statement to retrieve the <code>Base</code> property got really nasty. So I'd certainly like to accomplish this using TPH, if possible.</p>
  
  <p><strong>Update:</strong>
  I've verified that the problem exists in EF5 as well as EF6.</p>