Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You get an exception because you are not initializing the BrokerInstruments property of the Instrument class (meaning the value of that property is null). To fix that, you need a constructor on Instrument:</p> <pre><code>public Instrument() { BrokerInstruments = new HashSet&lt;BrokerInstrument&gt;(); } </code></pre> <p>Now if you want notification of an Instrument being added, that's a different problem. The easiest and safest way is to make the BrokerInstruments property getter return an IEnumerable, remove the setter, and add a <code>AddBrokerInstrument</code> method:</p> <pre><code>// With this, you don't need the constructor above. private ISet&lt;BrokerInstrument&gt; _brokerInstruments = new HashSet&lt;BrokerInstrument&gt;(); public virtual IEnumerable&lt;BrokerInstrument&gt; BrokerInstruments { get { return _brokerInstruments; } // This setter should allow NHibernate to set the property while still hiding it from external callers protected set { _brokerInstruments = new HashSet&lt;BrokerInstrument&gt;(value); } } public void AddBrokerInstrument(BrokerInstrument brokerInstrument) { // Any other logic that needs to happen before an instrument is added _brokerInstruments.Add(brokerInstrument); // Any other logic that needs to happen after an instrument is added } </code></pre> <p>I use an IEnumerable above because you want to indicate to the users of this function that they are not allowed to add instruments directly to the set- they need to call your method instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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