更好地理解级联。有人可以解释为什么在节点 C 和 D 以下的情况下没有持久化吗?谢谢。
public class Node : Entity
{
public virtual Node Previous { get; set; }
public virtual Node Next { get; set; }
public virtual string Name { get; set; }
public Node() { }
public Node(string Name)
{
this.Name = Name;
}
public virtual void Connect(Node Previous, Node Next)
{
this.Previous = Previous;
this.Next = Next;
}
}
映射:
public class NodeMap : IAutoMappingOverride<Node>
{
public void Override(AutoMapping<Node> mapping)
{
mapping.References(x => x.Previous).Cascade.SaveUpdate();
mapping.References(x => x.Next).Cascade.SaveUpdate();
}
}
数据创建:
INHibernateRepository<Node> NodeRepository = new NHibernateRepository<Node>();
Node A = new Node("A");
Node B = new Node("A");
Node C = new Node("C");
Node D = new Node("D");
Node E = new Node("E");
Node F = new Node("F");
A.Connect(null, B);
B.Connect(A, E);
C.Connect(B, E);
D.Connect(B, E);
E.Connect(B, F);
F.Connect(E, null);
NodeRepository.SaveOrUpdate(A);
NodeRepository.DbContext.CommitChanges();