C#C
C#3y 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.
Was this page helpful?