Domain Model I am working on has root aggregate and child entities. Something like the following code:
class Order
{
IList Lines {get;se
I have spent several days looking for a best approach for readonly lists in NHibernate. This discussion helped me a lot to form the one that fits our project.
There is an approach I started to use:
Code:
public class Order
{
private readonly IList lines = new List();
public virtual IEnumerable Lines
{
get
{
return new ReadOnlyCollection(lines);
}
}
public void AddLine(OrderLine line)
{
if (!lines.Contains(line))
{
this.lines.Add(line);
line.Order = this;
}
}
public void RemoveLine(OrderLine line)
{
if (lines.Contains(line))
{
this.lines.Remove(line);
line.Order = null;
}
}
}
public class OrderLine
{
public Order Order { get; set; }
}