Say I have the following DB structure:
asset: metadata_text:
id | type | source asset_id | font_size | font_color | font_name
----|------|----------- ----------|-----------|------------|-----------
0 | vid | http://... 2 | 24 | #FF8800 | Arial
1 | img | http://... ...
2 | text | null
...
metadata_vid: metadata_img:
asset_id | width | height | length asset_id | width | height
----------|-------|--------|-------- ----------|-------|--------
0 | 1920 | 1080 | 1303 1 | 400 | 400
... ...
I have assets with certain type
s, and each type
has a metadata table associated with it. An asset only has one entry in one of the metadata tables. How would I map an asset's metadata to a single property in EF core? I would like my Asset entity to look like
public class Asset
{
public long Id { get; set; }
public string Type { get; set; }
public string Source { get; set; }
public object Metadata { get; set; } // populate this with the entry from the relevant table
}
Is there any way to do this using EF Core? I understand that you can do type inheritance however this doesn't help my situation as it requires all metadata fields for all types to be in the same table as the assets. Any help is greatly appreciated!
Unfortunately table per type (TPT) inheritance is not supported in EF Core yet and this sounds like a great use case for it: GitHub TPT issue #2266
What would be the disadvantage of having a separate property for each?
There may then be a way to use AutoMapper to map all the properties to the properties of a single class within a model class. Or at least create your own mappings.