title: C# Dictionary key lookup in an InvariantCulture way
body: <p>My application handles some texts parsing and uses a proper noun cache to reduce database calls:</p>
  
  <pre><code>Dictionary&lt;String, ProperNoun&gt; ProperNounsDict;
  
  if (!ProperNounsDict.ContainsKey(word))
  {
      var newProper = new ProperNoun() { Word = word  };
      ProperNounsDict.Add(word, newProper);
  
      UnitOfWork.ProperNounRepository.Insert(newProper);
      try
      {
          UnitOfWork.SaveChangesEx();
      }
      catch (Exception ex)
      {
           // 
      }
  }
  </code></pre>
  
  <p>The problem is that database and C# treat equality of strings in a different way, so I can run into duplicate key error (SQL) for similar words:</p>
  
  <p><strong>1) Database</strong> (SQL Server 2014)</p>
  
  <pre><code>Column_name  Type       Collation
  Word         nvarchar   Latin1_General_100_CS_AS
  </code></pre>
  
  <p><code>Saevarsson</code> and <code>Sævarsson</code> are the same thing from the database perspective and it is fine for me, since words containing characters æ are very rare in parsed texts:</p>
  
  <pre><code>select * from dict.ProperNoun where Word = N'Saevarsson'  -- returns both Saevarsson and Sævarsson
  </code></pre>
  
  <p><strong>2) C#</strong></p>
  
  <pre><code>string s1 = "Sævarsson";
  string s2 = "Saevarsson";
  bool equals = s1.Equals(s2, StringComparison.InvariantCulture);
  </code></pre>
  
  <p>s1 and s2 are seen as equal, if comparison is done in an InvariantCulture way</p>
  
  <p><strong>Question: is there a way to check for a string key existence in an InvariantCulture way?</strong> I do not want to loose my O(1) complexity of checking for key existence, if possible.</p>
  
  <p>Things I have tried:</p>
  
  <p><strong>a) Database check</strong> - for cache misses, before inserting into the cache, also check in DB. Generates a lot of queries, so performance is awful</p>
  
  <p><strong>b) String normalization</strong> - replace undesired characters with "normal" ones using a map similar to <a href="https://stackoverflow.com/a/8464394/2780791">this one</a>. Requires a lot of work and I feel it can be automated since <code>StringComparison.InvariantCulture</code> knows how to deal with this.</p>
  
  <p>Thanks.</p>