views:

63

answers:

1

I have created a case insensitive dictionary in C Sharp as follows . And the following code throws an exception, since the dictionary is case insensitive.

IDictionary<string, ABCentre> names = new Dictionary<string, ABCentre>(StringComparer.OrdinalIgnoreCase);
        names.Add("LC001", new ABCentre());

        if (names.ContainsKey("lc001"))
        {
            names.Add("lc001", new ABCentre());// Exception , same key exists  
        }

But while mapping this dictionary(names) with some aggregation class in NHibernate, i am not able to get this exception. i.e., same text with different cases can be added to the keys .

Does the names dictionary, gets overridden with the one that NHibernate creates dynamically (using reflection), which is case sensitive.

Can some one suggest , how to map a case insensitive dictionary to NHibernate.?

thanks , vijay

+2  A: 

You'll have to create and map a custom collection to enable NHIbernate to use your collection type. NHibernate has its own implementation of IDictionary that it uses for collections mapped as map (NHibernate.Collection.PersistentGenericMap<TKey, TValue>).

Jamie Ide
Thanks Jamie , can you post a sample code on the same.
vijaysylvester
Sorry but the linked sample is the best I can do. I don't use custom collection types.
Jamie Ide