|
I have run into an issue mapping a dictionary to the DB where it is important that the dictionary keys use case-insensitive comparisons when checking for entries in the dictionary. The problem is that SQL server does perform case-insensitive comparisons when checking PK contraints but a default generic dictionary does not.
I need my dictionaries to behave like SQL server, so when I create them, I use the following...
IDictionary<string, string> _dataValues = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
So...
_dataValues.Add("APPLE", "RED"); // No problem.
_dataValues.Add("GRAPE", "PURPLE"); // No problem.
_dataValues.Add("Apple", "ALSO RED"); // EXCEPTION.
This is what I want. The problem is that when my objects are re-hydrated by NHibernate, they are placed into a dictionary that used the default string comparer, which is case-sensitive, and will allow the above operation.
Does anyone have any idea on how I can tell NHibernate to use CurrentCultureIgnoreCase as the comparer?
Thanks!
|