title: Two Keys and A Value in A Dictionary
body: <p>I've a requirement to implement two keys in a dictionary and stuck a bit. I am not sure if it's possible to do but my criteria is to make a search option using two keys to match in a dictionary data structure similar to the below Linq:</p>
  
  <pre><code>if(id &gt; 0 &amp;&amp; status != null)
  {
      var result = (from c in db.Employees
                    where c.EmployeeId == id &amp;&amp; c.Status == status
                    select c).ToList();
  }
  </code></pre>
  
  <p>With Dictionary, I've tried the following:</p>
  
  <pre><code>public class Employee
  {
     public int EmployeeId { get; set; }
     public string EmployeeName { get; set; }
     public string Address { get; set; }
     public string Status { get; set; }
  }
  
  public class TwoKeyDictionary&lt;k1, k2, T&gt; : Dictionary&lt;k2, Dictionary&lt;k2, T&gt;&gt;
  {
  
  }
  </code></pre>
  
  <p>Finally tried to the bind the Employee class with data and used List&lt;> for that:</p>
  
  <pre><code>List&lt;Employee&gt; employees = new List&lt;Employee&gt;()
  {
      new Employee { EmployeeId = 1001, EmployeeName = "John", Address = "On Earth", Status = "Active"},
      new Employee { EmployeeId = 1002, EmployeeName = "Jack", Address = "On Earth", Status = "Active"},
      new Employee { EmployeeId = 1003, EmployeeName = "James", Address = "On Earth", Status = "Inactive"},
      new Employee { EmployeeId = 1004, EmployeeName = "Oswald", Address = "On Earth", Status = "Inactive"}
  };
  
  int id = 0;
  string status = "" 
  
  if (id &gt; 0 &amp;&amp; status != "")
  {
      id = Convert.ToInt32(Console.ReadLine())
      status = Console.ReadLine().ToUpper();
  }
  
  TwoKeyDictionary&lt;int, string, List&lt;Employee&gt;&gt; dict = 
            employees.GroupBy(c =&gt; new { 
               CustomerId = c.EmployeeId, 
               c.Status })
           .ToDictionary(g =&gt; g.Key.CustomerId, g =&gt; g.Key.Status, g =&gt; g.ToList());
  
  foreach (var item in dict[id][status])
  {
      Console.WriteLine(item.CustomerId + " " + item.CustomerName); 
  }
  </code></pre>
  
  <p>It looks completed but right now, I am having exceptions and the one is: '<strong>Cannot convert to lambda expression to type System.Collections.Generic.IEComparer because it is not a delegate type</strong>' - ToDictionary(g => g.Key.CustomerId, g => g.Key.Status, <strong>g => g.ToList()</strong>. The other error in this line: var item in <strong>dict[id]</strong>[status]. Is there any way to get rid of it and may be doing the wrong thing somewhere.</p>