Hi,
I am creating a hierarchical tree using a self-joined table.
TreeTable (SQL Server):
Id (Primary Key) (identity)
ParentId (Foreign Key to Id)
Field1
Field2
Field3
My tree table initially has data for only the top level (e.g. Id = 1, ParentId = null...) and I
want to be able to add multiple lower levels in one UnitOfWork2.Commit.
TopLevel: Id = 1
OneLevelDownA: Id = not-yet-set
TwoLevelsDownOfA_A: Id = not-yet-set
TwoLevelsDownOfA_B: Id = not-yet-set
OneLevelDownB: Id = not-yet-set
TwoLevelsDownOfB_A: Id = not-yet-set
TwoLevelsDownOfB_B: Id = not-yet-set
I traverse through the tree and add all entities to the UnitOfWork2:
for each treeEntity (recursively...though recursion is not shown here)
{
Business.Lower.EntityClasses.TreeEntity treeEntity1 =
new Business.Lower.EntityClasses.TreeEntity();
treeEntity1.Field1 = "xx";
treeEntity1.Field2 = "yy";
treeEntity1.Field3 = "zz";
//treeEntity1.ParentId = ?; // HERE'S THE ISSUE/QUESTION
unitOfWork.AddForSave(treeEntity1);
}
The issue is that I cannot set the TwoLevelsDownOfA_AEntity.ParentId directly because
the OneLevelDownA.Id has not yet been set by the database (it's an identity field).
How can I set a relation between the parent entities and child entities, so the UnitOfWork2
will properly set the ParentIds?
Thanks!