❔ Polymorphic relationships in EF Core / .NET Core
I'm creating a spreadsheet-like app. At its most simple, I'm just displaying rows of models in a spreadsheet and letting the user update specific cells (columns).
I also need to implement a "highlight cell" feature. In something like Laravel, I'd create a polymorphic relationship. I imagine having a model called
Flag
with its table being Flags
and columns being something like Id
, FlaggableId
, and FlaggableType
(along with a few other fields holding data specific to the flag like what type of flag it is or notes on the flag). FlaggableType
points to the model (table) and FlaggableId
points to the row of that table.
The 2nd bit of complexity here is I also need to store the column that I'm flagging (highlighting), something like FlaggableColumn
.
Is this also something I can do in .NET? Any guidelines or tips on where to start with creating the model for this? I've read a few things about Discriminators
and TPH, TPT, and TPC. I'm a bit of a beginner in C# and .NET land and a few of the posts I found on the internet are a bit over my head.10 Replies
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Still trying to figure this out. Any thoughts?
Hi,
general advice: when u coding in dotnet try to not be a Laravel thinker, yes you can implement what u had learn in Laravel here and transfer this knowledge , however remember each community have their own preferences of doing things .
can i ask u why u want it to be a Morphic relationship?
This sounds a bit like an eav data model
hmmm, if i understand ur problem, u may take a look at TPC
take a look at this
https://devblogs.microsoft.com/dotnet/announcing-ef7-preview5/
Oh nice, nicer than eav
Still not flexible but eav is a pain at best especially in EF
kinda yah, but as u know there are always trade-offs
Eav is generally an anti pattern
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.