There are, say, an Attachments table with columns: id | ownerId | ownerType id | ownerId | ownerType id | ownerId | ownerType , which, respectively: primary key, foreign key and the table to which the foreign key belongs.
For example:
id | ownerId | ownerType --------------------------------- 1 1 Post 2 1 Comment Can EntityFramework be able to organize a link so that the output in the essence of the post and comment is a collection with their attachments? Sort of:
builder.Entity<Post>(). .HasMany(p => p.Attachments) .WithOne() .HasForeignKey(a => a.OwnerId); // and a.OwnerType = "Post" UPD: In the comments they advised to simply add the property of the collection of attachments to the necessary entities and entrust the rest to the EF itself. That's exactly what I did.
And then I wanted to add a third entity with attachments.
Does this solution look a bit strange? Already 3 foreign keys.

OwnerId, just not sure that producing two identical tables is the right way out = / - MrModestPostandCommenthave a common ancestor? - Andrew NOPAttachmentin thePostandComment, and entrust the implementation of this to EF? Trying to save on matches? - Andrew NOP