I have tree model us diffgram。 the model as below:
objects
---object
-----objects.
in the UI will be show as below:
Node1
--Node2
If i create Node1 & Node 2 and save them use below code is Ok:
public class DiffGramGenerator : Csla.DiffGram.DiffGramGenerator
{
public override void IntegrateGraph(IExportData root, DataItem dtoGraph)
{
if (root != null && root.IsParticipating)
{
if (root.Key == dtoGraph.Key)
{
if (root is ICollection)
{
HandleChilren(root, dtoGraph);
root.ImportFrom(dtoGraph);
}
else
{
if ((root as Csla.Core.ITrackStatus).IsDeleted)
{
HandleChilren(root, dtoGraph);
root.ImportFrom(dtoGraph);
}
else
{
root.ImportFrom(dtoGraph);
HandleChilren(root, dtoGraph);
}
}
}
else
throw new Exception("Root object keys don't match");
}
}
private void HandleChilren(IExportData root, DataItem dtoGraph)
{
foreach (var child in root.GetChildren().Where(c => c.IsParticipating))
{
var dto = (from d in dtoGraph.Children
where d.Key == child.Key
select d).SingleOrDefault();
if (dto != null)
IntegrateGraph(child, dto);
else
throw new Exception("Child key not in DTO graph");
}
}
}
If I get node1 and node 2 from database and use below code delete node1 and node2 (i delete node1, and backhind code delete the node2), It's work fine.
private void OnRemoveNode(ObjectViewModel row)
{
//row.IsExpanded = true;
if (row.Model .Children.Count > 0)
{
var temp = this.Model;
for (int i = row.Children.Count-1; i >=0; i--)
{
OnRemoveNode(row.Children as ObjectViewModel);
}
}
if (row.Parent is ObjectsViewModel)
{
(row.Parent as ObjectsViewModel).Objects.Remove(row);
DoRemove(row.Model);
}
else
{
(row.Parent as ObjectViewModel).Children.Remove(row);
(row.Parent as ObjectViewModel).Model.Children.Remove(row.Model);
}
}
but I create node 1,node2 and save them, then delete node1. will raise error. because var dto = dg.GenerateGraph(this) can not get the Node2. please give me and advise..
How to upload the source code to help me analyze this issue?
I found that created node1,node2 and save them, then delete node1 & node2 use OnRemoveNode method. the children's DeleteList is null.
but if the node1 & node 2 fetch from database, then delete node1 use OnRemoveNode to remove node1 & node2. the children's DeletedList is not null. cantains node2.
this problem trouble me several days.
It's Ok, I forget set ManageObjectLifetime = false within ObjectViewModel.
Copyright (c) Marimer LLC