Mapping inheritance structure in Entity Framework Core to Postgres - Conflicting Error Messages

ef-code-first ef-code-first-mapping ef-migrations entity-framework-core postgresql

Question

In my concept, there are many inheritance hierarchies. I'm working with a Postgres database and Entity Framework Core 3.1.2. First, Code. In order to produce my database tables, I'm attempting to make a migration.

My first abstract object was mapped.

public DbSet<Asset> Assets { get; set; }

I discover that a concrete descendent must be mapped before an abstract class may be mapped.

The corresponding CLR type for entity type 'Asset' is not instantiable and there is no derived entity type in the model that corresponds to a concrete CLR type.

I then plot the descendants.

public DbSet<LinearAsset> LinearAssets { get; set; }
public DbSet<StructureAsset> Structures { get; set; }
public DbSet<BridgeAsset> Bridges { get; set; }
public DbSet<RoadAsset> Roads { get; set; }

everything is in order. Fantastic.

However. I get into this strange circular argument where I must map the children and must not map them when I get to mapping my second inheritance tree (and any other that I attempt).

public DbSet<Attachment> Attachments { get; set; }
public DbSet<AssetAttachment> AssetAttachments { get; set; }

grants me

The entity type 'AssetAttachment' cannot be mapped to a table because it is derived from 'Attachment'. Only base entity types can be mapped to a table.

I'm back to this if I delete the AssetAttachments mapping.

The corresponding CLR type for entity type 'Attachment' is not instantiable and there is no derived entity type in the model that corresponds to a concrete CLR type.

The Asset inheritance structure, which worked, and the other inheritance hierarchies, which don't work, don't seem to be very different from one another.

I've tried a number of different methods for mapping or not mapping the descendant objects, but I always end up with one of the two errors mentioned above. I'm unsure of what Dot Net truly expects from me since I'm supposed to both map and not map the descendants.

Any advise on how to handle these two contradicting error messages would be much appreciated.

1
0
3/3/2020 5:34:12 AM

Accepted Answer

ZZZ_tmp
1
3/4/2020 6:13:52 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow