Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is done like this:</p> <p>Create your class like this:</p> <pre><code>public class Customer : Contact { private ISet&lt;Order&gt; _orders = new HashedSet&lt;Order&gt;(); public Collection&lt;Order&gt; Orders { return new List&lt;Order&gt;(_orders); } // NOrmally I would return a ReadOnlyCollection&lt;T&gt; instead of a Collection&lt;T&gt; // since I want to avoid that users add Orders directly to the collection. // If your relationship is bi-directional, then you have to set the other // end of the association as well, in order to hide this for the programmer // I always create add &amp; remove methods (see below) public void AddOrder( Order o ) { if( o != null &amp;&amp; _orders.Contains(o) == false ) { o.Customer = this; _orders.Add(o); } } } </code></pre> <p>in your mapping, you specify this:</p> <pre><code>&lt;set name="Orders" table="OrdersTable" access="field.camelcase-underscore" inverse="true"&gt; &lt;key column="..." /&gt; &lt;one-to-many class="Order" .. /&gt; &lt;/set&gt; </code></pre> <p>Since you use inheritance, you should definitly have a look at the different posibilities regarding inheritance-mapping in NHibernate, and choose the strategy that is best suited for your situation: <a href="http://www.nhforge.org/doc/nh/en/index.html#inheritance" rel="nofollow noreferrer">inheritance mapping</a></p> <p>Regarding set &amp; bag semantics: - when you map a collection as a set, you can be sure that all the entities in the mapped collection, are unique. That is, NHibernate will make sure that, while reconstituting an instance, the collection will not contain duplicates. - when you map the collection as a bag, it is possible that your collection will contain the same entity more then once when loading the object from the DB.</p> <ul> <li>A Set is a collection of distinct objects considered as a whole. A valid example of a set (of letters) is: { a, b, c, d }. Each letter occurs exactly once.</li> <li>A Bag is a generalization of a set. A member of a bag can have more than one membership while each member of a set has only one membership. A valid example of a bag is { a, a, a, b, c, c, d, ...}. The letters a and c appear more than once in the Bag.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload