I have the following class, where NextNode points to another instance of the Node class:
public class Node
{
public int Id { get; set; }
public int? NextNodeId { get; set; }
public Node? NextNode { get; set; }
...
}
Since I can't reference a node that doesn't yet exist in the NextNode property, is it possible to seed the database in two steps?
First create, the nodes, and then second, populate the NextNode property?
Since you will generate the Ids you can simply fill in the
NextNodeId's without fillingNextNodeforHasData:If you decide to create custom seeding code with
Add(Range)+SaveChanges(Async)then you can just create corresponding hierarchy and add it, EF should be able to handle this: