I am using the table per type strategy with a class named Assets as my super-type and another class PropertyAsset inheriting it. However, there are two classes inheriting the PropertyAsset class, named InternalProperty & ExternalProperty.
Asset Table
public class Asset : Entity, IMustHaveCompany
{
public int CompanyId { get; set; }
public string? SerialNumber { get; set; }
public decimal ExpectedLife { get; set; }
public decimal EstimatedValue { get; set; }
public DateTime PurchaseDate { get; set; }
#region Navigation Properties
public virtual Company.Company? Company { get; set; }
#endregion
}
Property Asset Table
public class PropertyAsset : Asset
{
public int Rooms { get; set; }
public int Bathrooms { get; set; }
public decimal LeaseRate { get; set; }
public decimal SqFeet { get; set; }
}
External Property Table
public class ExternalProperty : PropertyAsset
{
public decimal LeaseRatePerSquareFt { get; set; }
public decimal SquareFoot { get; set; }
public decimal AnnualIncome { get; set; }
public decimal MonthlyLease { get; set; }
}
Internal Property Table
public class InternalProperty : PropertyAsset
{
public decimal PurchasePrice { get; set; }
public PaymentMethod PaymentMethod { get; set; }
public decimal DownPayment { get; set; }
public decimal PaymentsRemaining { get; set; }
public decimal Borrowing { get; set; }
public decimal AnnualTax { get; set; }
}
How would I create let's say the InternalProperty entity using this approach, with the values reflecting upwards? My thoughts are that I would need to use a DTO and map it with AutoMapper, but when thinking about it, I doubt that approach will work, or if it would, I'd need to create three entities separately (InternalProperty, then PropertyAsset and somehow use the Id of the newly created internal property, and then finally the Asset table itself.)
Am I using the TPT approach incorrectly in this instance?