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");
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: