I have the following schema (abbreviated to relevant code)
class Person
{
public int Id {get;set;}
public string Name {get;set;}
public ICollection<MetaData> MetaData {get;set;}
}
class Car
{
public int Id {get;set;}
public string Make {get;set;}
public ICollection<MetaData> MetaData {get;set;}
}
class Building
{
public int Id {get;set;}
public string Address {get;set;}
public ICollection<MetaData> MetaData {get;set;}
}
class MetaData
{
public int Id {get;set;}
public string CLRType {get;set;}
public string Value {get;set;}
// These two fields together form a connection to the other entities
public int Key {get;set;} // the PK of the connected entity
public string Type {get;set;} // nameof(Entity)
}
How can I represent this in EF Core?
Using OwnsMany
create a table per type+metadata type connection
If I try using TPH, then the metadata table ends up with additional fields per connected entity
Neither of those solutions are ideal for me. I do not need restraints in the database, I just want a way to express this relation in such a way that EF Core will be able to hydrate my models Even if I have to provide the sql manually (even for both reads and writes) that would be workable
If this is not possible with the existing APIs provided, is there a way I can write extensions on my own that will do what I need?