I have two classes ElementData
and Socket
.
- An
ElementData
can have multipleSocket
s - A
Socket
can have anElementData
So you can nest a series of ElementData
.
The classes look like this:
public class ElementData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Type { get; set; } = string.Empty;
public string Category { get; set; } = string.Empty;
public List<SocketData>? Sockets { get; set; } = new List<SocketData>();
}
public class SocketData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Alias { get; set; } = string.Empty;
public int ParentElementId { get; set; }
public ElementData ParentElement { get; set; } = new ElementData();
public int ChildElementId { get; set; }
public ElementData ChildElement { get; set; } = new ElementData();
public string ValidElementTypes { get; set; } = string.Empty;
}
But if I create a migration, it just connects the ChildElement
to the parent element and only create ChildElementId
row in the database.
I was hoping for a database table with columns
[Id], [Alias], [ParentElementId], [ChildElementId], [ValidElementTypes]
where ParentElement
has a foreign key to parent ElementData
, and the ChildElement
has a foreign key to child ElementData
.
How do I accomplish this?
Thanks in advance :-)