C
C#15mo ago
schwartzmj

❔ 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
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
schwartzmj
schwartzmj15mo ago
Still trying to figure this out. Any thoughts?
Black Knight
Black Knight15mo ago
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?
Mayor McCheese
Mayor McCheese15mo ago
This sounds a bit like an eav data model
Black Knight
Black Knight15mo ago
hmmm, if i understand ur problem, u may take a look at TPC
Mayor McCheese
Mayor McCheese15mo ago
Oh nice, nicer than eav Still not flexible but eav is a pain at best especially in EF
Black Knight
Black Knight15mo ago
kinda yah, but as u know there are always trade-offs
Mayor McCheese
Mayor McCheese15mo ago
Eav is generally an anti pattern
Accord
Accord15mo ago
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.