-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Ability to define custom joins (for readonly navigations) #33171
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@domagojmedo why have TableName on Metadata in the first place? Blog (and presumably Post) already reference a specific Metadata.RowId via the foreign key, what's the purpose of having |
Yes yes, RowId isn't really FK, it can reference many tables depending on TableName column |
To avoid having N FK columns on the table, 1 for each table that can have a row in metadata table, we have this kind of "soft" foreign key |
But why not just reference Metadata.Id directly from a Blog.MetadataId foreign key (and similarly from Post.MetadataId)? That allows a very simple, classical one-to-many relationship, where each Blog/Post just references its Metadata row? |
But 1 blog can have many Metadata associated with it. It's 1 to N from the other side. Another example is an audit table where you save a json diff of row when it's updated. You can have many updates for the same row |
duplicate of #7623? |
@MoishyS No, while there is some overlap in scenarios the implementation would likely be very different |
This boils down to polymorphic associations, which I would also like to vote for. It is already possible with Laravel and Ruby on Rails. |
Not sure if it's currently possible, but would be nice to be able to define a "custom join" maybe.
Say we have a table
Metadata
and that table has PK Id and columnsRowId
,TableName
andData
.We also have tables
Blog
andPost
.In
RowId
we write down PK of the table with name inTableName
. It would then be nice if we could explain to EF how to join from our tablesBlog
andPost
to tableMetadata
.If we have
List<Metadata> Metadatas
inBlog
, we should be able to define inModelBuilder
that when we accessBlog.Metadatas
it would join byBlog.Id = Metadata.RowId and Metadata.TableName = 'Blog'
.I guess there is an issue with what happens if you want to add a
Metadata
entity toMetadatas
list onBlog
orPost
🤷The text was updated successfully, but these errors were encountered: