What is the best practice for readonly lists in NHibernate

后端 未结 5 1708
北荒
北荒 2020-12-06 02:32

Domain Model I am working on has root aggregate and child entities. Something like the following code:

class Order
{
   IList Lines {get;se         


        
5条回答
  •  天命终不由人
    2020-12-06 02:46

    I expose collections as ReadOnlyCollection and use AddX and RemoveX methods for maintaining the collections. We just switched to 3.5 and I'm thinking about exposing IEnumerable instead. In most cases with NHibernate the child has a reference to the parent so exposing Add and Remove methods allows you to maintain that relationship:

        public void AddPlayer(Player player)
        {
            player.Company = this;
            this._Players.Add(player);
        }
    
        public void RemovePlayer(Player player)
        {
            player.Company = null;
            this._Players.Remove(player);
        }
    

提交回复
热议问题