I have a dictionary like this:
var dic = Dictionary<Collection<MyObject>, string>
Then I add an entry like this:
dic.Add(myObjColl, "1");
where myObjColl contains a single entry
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.
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.
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.
To elaborate a bit on my issue:
I have a collection of product row objects. Each with a product identification object consisting of a collection of key value pairs:
Collection<ProductKeyValuePair> productIdentification;
myProductRow.ProductIdentification = productIdentification;
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.
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 :-/