I Have a tree. I add new node1 and new node2 as below
node 0
-node1
--node2
when i save , throw Exception. i checked it and fund the BLB save the node2 firstly. so the node2's parentId does not exist in the database.
in the root list, code as below.
public override void BeginSave(EventHandler<Csla.Core.SavedEventArgs> handler, object userState)
{
var dg = new Csla.DiffGram.DiffGramGenerator();
var dto = dg.GenerateGraph(this);
var cmd = new SaveObject { DiffGram = dto };
cmd = DataPortal.Execute<SaveObject>(cmd);
dg.IntegrateGraph(this, cmd.DiffGram);
base.BeginSave(handler, userState);
}
[Serializable]
private class SaveObject : CommandBase<SaveObject>
{
public Csla.DiffGram.DataItem DiffGram { get; set; }
protected override void DataPortal_Execute()
{
//do insert/update/delete operations on entire diffgram
}
}
in the child code as below:
protected override void ImportFrom(Csla.DiffGram.DataItem dto)
{
if (dto.IsNew)
InsertItem();
else if (dto.IsDeleted)
DeleteItem();
else
UpdateItem();
}
how to update the parent node firstly?
I use Csla 4.2.0
Any Advise?
The diffgram sample is a sample, nothing more. If you care about the order in which the items are inserted/updated in the database, then you need to control the order in your code.
Copyright (c) Marimer LLC