You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
changed the title [-]Reference to Type spanning across several entity types (and therefore tables)[/-][+]Support Polymorphic Relationships[/+]on Feb 22, 2017
It's not currently supported, unless Post/Tag have a common base type (but that means they would need to be stored in the same table with TPH... presumably not what you want 😄). We have discussed supporting this, but it's not something we're working on at the moment or in the immediate future. Moving to the backlog.
Order
Id UNIQUEIDENTIFIER
OrderLine
Id UNIQUEIDENTIFIER
OrderId UNIQUEIDENTIFIER
Connection
Id UNIQUEIDENTIFIER
FromEntityId UNIQUEIDENTIFIER
ToEntityId UNIQUEIDENTIFIER
It allows linking any table to any other table via the Connection table. The alternative being to create a ConnectionFromTxToTy table for every single combination. Which in our schema means creating 70! (! for factorial) tables just for this functionality. On top of this that would mean adding 70 navigation properties to every class. This is far from easy to implement or consume.
It is possible to add a navigation property Connections to my models. Which does allow me to view all Connections linked to a single entity (provided I double them up).
However, I'd like to go one step further and actually be able to include the linked entity, like any other entity. The downside of course is that this is not supported by EntityFrameworkCore. I cannot create a class like below and expect it to work out of the box.
And as soon I would try to include on Orders.Include(order => order.Connections).ThenInclude(connection => connection.ToEntity) I would lose all typed functionality. But this I could live with if something like the following would function: Orders.Include(order => order.Connections).ThenInclude(connection => connection.ToEntity).ThenInclude(orderLine => ((OrderLine)orderLine).Order).
Currently I've included the linked entity as JSON, but that obviously means I lose all include functionality after that. But worse than that, any ValueConverters I assigned to that type aren't being executed.
How can I tackle this challenge? I'm not sure what's the best path: the virtual IDictionary<string, object> route or the virtual object route or something else. I feel like I might potentially get there with a custom QueryModelGenerator and a custom SqlServerQuerySqlGeneratorFactory, although I don't know if that alone would be enough. But EntityFrameworkCore stops me already at the navigation property with type object.
Sounds like a relational database isn't the right tool for the job, honestly ...
Reacted by Rafael Veronezi, Alexander Trauzzi, PasVV, matt beary, Mahmoud Masri, Niklas, Frane Jakelić, EL MCHERQUI, Lilian ARAGO, PeterMaco and 13 more
I'd definitely like to see polymorphic relations supported and if the number of times it's asked for even in this project's bug tracker is any indicator... It's quite high priority.
@AndriySvyryd - I've been scanning this repository as well as stack overflow (as well as others) and the combined organic demand is a much different story.
I get you're trying to be objective, but that methodology leans into a disingenuous extreme. It takes empathy to truly understand what users want, not the expectation that people find the right place to put a "thumbs up" as well as to self-select in such a specific way.
Hopefully feature priority for this project can be more visionary, not reactionary...
Right, but I don't want it to become a bad-faith distraction to my point which is that I think demand for this in particular is more than the most accessible metric.
My apologies, but also in my defence, I do have a knack for thesethings.
We are gathering feedback to make sure that we don't miss any gaps not currently reflected in the issues. We'll adjust our plans if necessary according to the data.
Hmm. That's really no different to waiting for +1s. It substitutes analysis & intuition with statistics and intellect. This goes back to my previous point about being visionary and not reactionary.
I get it, the next thing to say is that if people don't speak up, they can't be helped... But then what is the long term impact of that and what blind spots does it create? Current sentiment towards EF core is hurting .net in general and quite a few long-term asks have been sitting in the freezer since 2014.
The impression given here is that the data is bad due to a bad methodology and it's pulling focus away from the things people actually want.
@atrauzzi we aren't just looking at data - analysis and intuition are also telling us that certain other issues are probably more important to our users (the thing about intuition is that it's a bit hard to substantiate 🤣). I also don't believe in purely data- and metric-driven decisions, but I don't think this project does that in general. It's easy to say that a certain feature is important or has been in the backlog for a long time. What's hard is to gauge its importance compared to everything else that users want.
Reacted by Alexander Trauzzi, Arthur Vickers, Marcel Bradea and Kei
posts
id - integer
title - string
body - text
videos
id - integer
title - string
url - string
comments
id - integer
body - text
commentable_id - integer
commentable_type - string
#15854 (comment) would be a workaround but that's also not planned, any workaround for now?
Reacted by Alexander Trauzzi, Esther-St, Greg Zapp, shyn, MoishyS, Kei, Tomáš Petržela, Rj Lacanlale and Jannatul Nayeem
I'm going to also request this. Especially since #25141 was rolled into it.
EF Core is supposed to be something usable by large organizations. Yet a consequence of that environment is we often don't get to adjust the DB to what a library expects. DBAs don't like the performance impact of adding a column where every value is the same, and probably see forcing the use of raw SQL and stored procedures as a plus.
Reacted by Alexander Trauzzi, Vlad Rudenko, tb-mtg, jamezamm, Samuel, TheWrightDev, David Faivre, Tomáš Petržela, Andreas Gullberg Larsen, MattGeller and 2 more
I have an issue involving this that I managed to work around via a switch clause and TPH (not pretty but worked). This would be very nice to have moved forward. I don't have much to add, but #25141 is what I need to clean it up. Thanks in advance. Hopefully, it happens in this year or next. It's been on the backburner for a long time and has gotten a lot of planning, so who knows.
Activity
[-]Reference to Type spanning across several entity types (and therefore tables)[/-][+]Support Polymorphic Relationships[/+]rowanmiller commentedon Feb 22, 2017
It's not currently supported, unless Post/Tag have a common base type (but that means they would need to be stored in the same table with TPH... presumably not what you want 😄). We have discussed supporting this, but it's not something we're working on at the moment or in the immediate future. Moving to the backlog.
bdebaere commentedon May 28, 2019
Copied from my StackOverflow post.
bjorn-ali-goransson commentedon May 28, 2019
Hey,
Sounds like a relational database isn't the right tool for the job, honestly ...
bricelam commentedon Jul 29, 2020
See also #757
atrauzzi commentedon Oct 31, 2020
I'd definitely like to see polymorphic relations supported and if the number of times it's asked for even in this project's bug tracker is any indicator... It's quite high priority.
AndriySvyryd commentedon Oct 31, 2020
@atrauzzi This issue currently only has 9 👍 votes, so it's actually rather low on the feature request list
atrauzzi commentedon Oct 31, 2020
@AndriySvyryd - I've been scanning this repository as well as stack overflow (as well as others) and the combined organic demand is a much different story.
I get you're trying to be objective, but that methodology leans into a disingenuous extreme. It takes empathy to truly understand what users want, not the expectation that people find the right place to put a "thumbs up" as well as to self-select in such a specific way.
Hopefully feature priority for this project can be more visionary, not reactionary...
AndriySvyryd commentedon Oct 31, 2020
Yes, we take more thing into account for the release planning process, this is just the most accessible metric.
atrauzzi commentedon Nov 1, 2020
Right, but I don't want it to become a bad-faith distraction to my point which is that I think demand for this in particular is more than the most accessible metric.
My apologies, but also in my defence, I do have a knack for these things.
AndriySvyryd commentedon Nov 1, 2020
We are gathering feedback to make sure that we don't miss any gaps not currently reflected in the issues. We'll adjust our plans if necessary according to the data.
atrauzzi commentedon Nov 1, 2020
Hmm. That's really no different to waiting for +1s. It substitutes analysis & intuition with statistics and intellect. This goes back to my previous point about being visionary and not reactionary.
I get it, the next thing to say is that if people don't speak up, they can't be helped... But then what is the long term impact of that and what blind spots does it create? Current sentiment towards EF core is hurting .net in general and quite a few long-term asks have been sitting in the freezer since 2014.
The impression given here is that the data is bad due to a bad methodology and it's pulling focus away from the things people actually want.
roji commentedon Nov 1, 2020
@atrauzzi we aren't just looking at data - analysis and intuition are also telling us that certain other issues are probably more important to our users (the thing about intuition is that it's a bit hard to substantiate 🤣). I also don't believe in purely data- and metric-driven decisions, but I don't think this project does that in general. It's easy to say that a certain feature is important or has been in the backlog for a long time. What's hard is to gauge its importance compared to everything else that users want.
9 remaining items
SoftCircuits commentedon Oct 2, 2023
@ajcvickers
I didn't understand your sample code. How is the relationship between Employees and Documents mapped in the database? I don't see any foreign keys.
Also, was anything new added to .NET to better support this since you posted that?
Thanks.
MoishyS commentedon Nov 9, 2023
I am surprised that it's still not in plan, Laravel has had it for like 10 years already.
https://laravel.com/docs/master/eloquent-relationships#one-to-many-polymorphic-relations
#15854 (comment) would be a workaround but that's also not planned, any workaround for now?
EmperorArthur commentedon Feb 13, 2024
I'm going to also request this. Especially since #25141 was rolled into it.
EF Core is supposed to be something usable by large organizations. Yet a consequence of that environment is we often don't get to adjust the DB to what a library expects. DBAs don't like the performance impact of adding a column where every value is the same, and probably see forcing the use of raw SQL and stored procedures as a plus.
da3dsoul commentedon Feb 19, 2025
I have an issue involving this that I managed to work around via a switch clause and TPH (not pretty but worked). This would be very nice to have moved forward. I don't have much to add, but #25141 is what I need to clean it up. Thanks in advance. Hopefully, it happens in this year or next. It's been on the backburner for a long time and has gotten a lot of planning, so who knows.