C#C
C#16mo ago
Saiyanslayer

✅ Designing a configurable object in EF Core

Hi everyone!

My goal is to have an object for a web project where you can configure the fields it has:
public class Structure {
   public int Id;
   public string Name;
   public Property[] Properties; // each value to show/edit
   public Structure[] Structures; // in the future, can also contain other Structure objects
}

public class Property<TValue> {
   public int Id;
   public string Name;
   public T Value;
}


This would let me design a "Patient" object:
new Structure(Id:"1", Name:"Patient")


I could add properties:
var properties = {
  new Property<string> {Id = 1, Name = "Patient Name", Value = "John Doe"},
  new Property<string> {Id = 2, Name = "Patient Id", Value = "007"},
  new Property<DateTime> {Id = 3, Name = "Patient Birthday", Value = "2024-09-22"}
}


What would be a good approach in EF Core to this? Table-Per-Hierarchy? How can I map the TValue generic properly?
Was this page helpful?