c# - instantiating an nhibernate Collection -
in order entity getting null ref on orderitems. occurs when order first created. i'd able add like
order.orderitems = new iesi.collections.set<orderitem>();
the error "cannot access protected constructor "set" here
public class order { public virtual int id { get; set; } public virtual iset<orderitem> orderitems { get; set; } public virtual void addorderitem(orderitem item) { item.order = this; // orderitems below null orderitems.add(item); } } <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="estore.domain" namespace="estore.domain.model"> <class name="order" table="orders"> <id name="id" type="int32" column="id" unsaved-value="0"> <generator class="identity"/> </id> <property name="username" column="username"/> <set name="orderitems" table="orderitems" generic="true" cascade="all-delete-orphan" inverse="true" > <key column="orderid" not-null="true" /> <one-to-many class="estore.domain.model.orderitem, estore.domain" /> </set> </class> </hibernate-mapping>
set orderitems new list in constructor
public order() { orderitems = new list<orderitem>(); }
Comments
Post a Comment