title: Entity Framework Code First: Table Per Hierarchy, doesn't popluate custom discrimiator field
body: <p>I am using Table Per Hierarchy (TPH) architecture to work with an existing database schema. When I attempt to use a custom <em>Discriminator</em> field name a <em>DbEntityValidationException</em>:</p>
  
  <blockquote>
    <p><em>Property: CourseType Error: The CourseType field is required.</em></p>
  </blockquote>
  
  <h3>Models</h3>
  
  <pre><code>public abstract class Course {
      public int ID { get; set; }
      public string Name { get; set; }
      public string CourseType { get; set; }
  }
  public class OnlineCourse : Course {
      public string Url { get; set; }
  }
  public class OnsiteCourse : Course {
      public string Location { get; set; }
  }
  </code></pre>
  
  <h3>Entity Type Configurations</h3>
  
  <pre><code>public class CourseMap : EntityTypeConfiguration&lt;Course&gt; {
      public CourseMap() {
          this.HasKey(x =&gt; x.ID);
          this.Property(x =&gt; x.Name).HasMaxLength(100).IsRequired();
          this.Property(x =&gt; x.CourseType).HasMaxLength(128).IsRequired();
      }
  }
  public class OnlineCourseMap : EntityTypeConfiguration&lt;OnlineCourse&gt; {
      public OnlineCourseMap() {
          this.Property(x =&gt; x.Url).HasMaxLength(500);
      }
  }
  public class OnsiteCourseMap : EntityTypeConfiguration&lt;OnsiteCourse&gt; {
      public OnsiteCourseMap() {
          this.Property(x =&gt; x.Location).HasMaxLength(100);
      }
  }
  </code></pre>
  
  <h3>Data Context</h3>
  
  <pre><code>public class EntityContext : DbContext {
  
      public EntityContext(): base("Name=EntityContext") {
      }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder) {
          modelBuilder.Configurations.Add(new CourseMap());
          modelBuilder.Configurations.Add(new OnlineCourseMap());
          modelBuilder.Configurations.Add(new OnsiteCourseMap());
  
          modelBuilder.Entity&lt;Course&gt;()
              .Map&lt;OnlineCourse&gt;(x =&gt; x.Requires("CourseType").HasValue("Online"))
              .Map&lt;OnsiteCourse&gt;(x =&gt; x.Requires("CourseType").HasValue("Onsite"));
      }
  
      public DbSet&lt;Course&gt; Courses { get; set; }
  }
  </code></pre>
  
  <h3>Code Executed</h3>
  
  <pre><code>using (var ctx = new EntityContext()) {
      ctx.Courses.Add(new OnlineCourse() {
          Name = "Online 1",
          Url = "Http://www.online.com"
      });
      ctx.SaveChanges();
  }
  </code></pre>