For background, let’s say I have two classes:
public class OrderType1 : ModelBase
{
public string Customer { get; set; }
}
public class OrderType2 : ModelBase
{
public string Customer { get; set; }
}
Then one class that can hold a reference to either of these types, based on a base class ModelBase
which does not have the Customer
field in it.
public class ScheduledOrder : ModelBase
{
public int ClientId { get; set; }
[JsonIgnore]
[ForeignKey(nameof(ClientId))]
public virtual Client Client { get; set; }
public int OrderType { get; set; }
public int? TemplateId { get; set; }
// This can be either OrderType1 or OrderType2
[JsonIgnore]
[ForeignKey(nameof(TemplateId))]
public Virtual ModelBase Template { get; set; }
}
I want to be able to include Template when I retrieve a ScheduledOrder from the database so that I can access the Customer field of either class, and maybe do specific things with each derived class.
When I attempt this I get errors in OnConfiguring
of a completely different type and it looks unrelated.
My question is is something like this even possible? I want to avoid having to query the database again using an OrderType property or something.
6