Hello Everyone,

I am new to NHibernate and have a seemingly simple question. I need to
avoid cycles in a tree structure (of folders, for example). My setter
for the ParentFolder looks something like this:

        public virtual Folder ParentFolder
        {
            get { return _ParentFolder; }
            set
            {
                if (!value.Equals(_ParentFolder))
                {
                    Folder parent = value;
                    while (parent != null)
                    {
                        if (parent.Equals(this)) throw new Exception
("Cycle");
                        parent = parent.ParentFolder;
                    }
                    _ParentFolder = value;
                }
            }
        }

However, this kind of protection does not avoid cycles with 100%
certainty. If (business) transaction#1 puts Folder A below Folder B
and a separate transaction#2 puts Folder B below Folder A, then both
transactions will pass, resulting in a persisted cycle.

How would you handle such a situation? Any simple solution without
making the entire tree the aggregate root and not allowing
simultaneous changes to the trees structure (i.e. I would prefer a
more "optimistic" approach to protecting the entire tree)?

thanks and enjoy,
ramin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to