'Entity framework core override property issue

I have 2 classes

public class Offering
{
  [Required]
  [JsonPropertyName("startDate")]
  public virtual DateTime StartDate { get; set; }

  [Required]
  [JsonPropertyName("endDate")]
  public virtual DateTime EndDate { get; set; }
}
public class ComponentOffering : Offering
{
 [Required]
 [JsonPropertyName("startDateTime")]
 public override DateTime StartDate { get; set; }

 [Required]
 [JsonPropertyName("endDateTime")]
 public override DateTime EndDate { get; set; }
}

In EF Core Table-per-hierarchy when I add values to properties StartDate and EndDate in ComponentOffering model and save it to database I get default DateTime values saved.

Any ideas ?

NOTE : Mappings

modelBuilder.Entity<ComponentOffering>()
                .Property(c => c.StartDate)
                .HasColumnName("StartDate");
modelBuilder.Entity<ComponentOffering>()
                .Property(c => c.EndDate)
                .HasColumnName("EndDate");


Solution 1:[1]

You need ignore abstract class mapping. After that you can map your concrete class property normally.

Using Fluent API it would look something like this:

public void Configure(EntityTypeBuilder<Offering> builder)
{
    builder.ToTable("Offerings");

    builder.Ignore(x => x.StartDate);
    builder.Ignore(x => x.EndDate);
}


public void Configure(EntityTypeBuilder<ComponentOffering> builder)
{
    builder.ToTable("Offerings");

    builder.Property(x => x.StartDate).IsRequired(true);
    builder.Property(x => x.EndDate).IsRequired(true);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lucas dos Santos