Note that there are some explanatory texts on larger screens.

plurals
  1. POCollection as key in Dictionary
    text
    copied!<p>I have a dictionary like this:</p> <pre><code>var dic = Dictionary&lt;Collection&lt;MyObject&gt;, string&gt; </code></pre> <p>Then I add an entry like this:</p> <pre><code>dic.Add(myObjColl, "1"); </code></pre> <p>where myObjColl contains a single entry</p> <p>On the second run I try to add another entry to dic where myObjColl has two entries (one of them the same as the one in the first run) and I get an exception that the key already exists.</p> <p>What am I missing here? I expect the dictionary key to be a collection and surely two collections with different number of entries cannot be identical.</p> <p>EDIT: What happened was that myObjColl was initialized outside a foreach and during the second iteration updated. So what I thought was a NEW collection with two entries was actually the old one entry collection with an additional entry added.</p> <p>To elaborate a bit on my issue:</p> <p>I have a collection of product row objects. Each with a product identification object consisting of a collection of key value pairs:</p> <pre><code>Collection&lt;ProductKeyValuePair&gt; productIdentification; myProductRow.ProductIdentification = productIdentification; </code></pre> <p>I then have to construct another collection of ProductKeyValuePairs defining the "owner" of each product row object (one product row object can have multiple owners) and I need to add each owner to the correspoding procuct row object(s). A traditional many to many where the common key is a collection of KeyValuePairs.</p> <p>Hard to explain but it's really down to legacy data returned from old systems running on a mainframe and most likely stored in a hierarchical database of some sort :-/</p>
 

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