From the NHibernate docs:
NHibernate requires that persistent collection-valued fields be declared as an interface type
I don't really understand why. If your collection implements ICollection shouldn't this suffice?
Consider a class which holds a collection of items:
Code:
public class Customer
{
private ICollection orders;
public ICollection Orders
{
get { return orders; }
set { orders = value; }
}
}
This all works nicely with NHibernate - the only thing is that I want orders to be a concrete type (eg OrderList:CollectionBase) and not an ICollection
If I change it to OrderList I receive a cast exception.
What is the "correct" way to do this so Orders is exposed as an OrderList and not generic ICollection.
Yes I realise OrderList is NOT an interface type but I don't understand why NHibernate requires this.