I'm designing a .NET Core application using EF Core with a MySQL database, following a Table-per-Type (TPT) inheritance strategy.
I have a base Report class with several derived types such as QualityReport, MaintenanceReport, SafetyReport, etc. As expected with TPT, each derived type maps to its own table.
I want to implement a custom audit system that logs every update to any Report or its derived types. showing the old and new values when a record is updated, or deleted.
I know that SQL Server supports system-versioned (temporal) tables for this kind of use case, but since I'm using MySQL, that option isn't available.
What path should I follow to implement a reliable, property-level audit system that captures all changes across TPT entities in EF Core with MySQL?
// Base report class with polymorphism
[Table("Reports")]
[JsonPolymorphic(TypeDiscriminatorPropertyName = "Type")]
[JsonDerivedType(typeof(QualityReport), "qualityReport")]
[JsonDerivedType(typeof(MaintenanceReport), "maintenanceReport")]
[JsonDerivedType(typeof(SafetyReport), "safetyReport")]
public abstract class Report
{
[Key]
public int Id { get; set; }
[Required]
public DateTime CreatedDate { get; set; }
[Required]
public DateTime UpdatedDate { get; set; }
[Required, MaxLength(200)]
public string Title { get; set; } = null!;
[Required, MaxLength(100)]
public string CreatedBy { get; set; } = null!;
[MaxLength(100)]
public string? UpdatedBy { get; set; }
}
public class QualityReport : Report
{
public string QualityMetric { get; set; }
public string InspectorName { get; set; }
public DateTime InspectionDate { get; set; }
public string Summary { get; set; }
public int SeverityLevel { get; set; }
}