I've got a private field in a Department class that is a SortedSet,
which is made available to clients as an ImmutableSet, like so:

        protected ISet<StaffMember> _employees = new
SortedSet<StaffMember>();

        public virtual ISet<StaffMember> Employees {
            get { return new ImmutableSet<StaffMember>(_employees); }
            protected set { _employees = value; }
        }

This does make the Employees property readonly, but I'm getting an
error from NHibernate saying that the list is immutable when I try to
add to the list, for which I have the following method:
        public virtual void AddEmployee(StaffMember staffMember)
{ _employees.Add(staffMember); }

The primary consumer of this method right now is the StaffMember class
on the other side of the relationship. It has a Department reference
which looks like:
        private Department _department;
        public virtual Department Department {
            get { return _department; }
            set {
                if(_department == null || _department.Equals(value)
throw new ArgumentException(...);
                _department = value;
                _department.AddEmployee(this);
            }
        }

I might not have mapped the relationship properly, but is there a
better way to expose the set than with an ImmutableSet to make it
readonly?

Thanks for sharing,
Berryl

--~--~---------~--~----~------------~-------~--~----~
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