title: How to query a nested object dictionary against another dictionary key/values matching
body: <p>I need to query a dictionary that is within an object and bring back certain records based on a dictionary that is passed in.</p>
  <p>I know there is a <code>.ContainsKey()</code>, but I need to check the Key/Value match against each other.</p>
  <p>I think it needs to be a <code>KeyValuePair</code>, but how to I convert a Dictionary&lt;string, string&gt; to KeyValuePair.</p>
  <p>What is the best way to do this? Or is it even possible?</p>
  <p>Code:</p>
  <pre><code>    public class MyFiles
      {
          public int Id { get; set; }
          public string FileName { get; set; }
  
          public IDictionary&lt;string, string&gt; Metadata { get; set; } = new Dictionary&lt;string, string&gt;();
      }
  </code></pre>
  <pre><code>        private void button1_Click(object sender, EventArgs e)
          {
              var list = new List&lt;MyFiles&gt;();
  
              list.Add(new MyFiles
              {
                  Id = 1,
                  FileName = &quot;myTestfile.jpg&quot;,
                  Metadata = new Dictionary&lt;string, string&gt;
                  {
                      { &quot;FileSize&quot;, &quot;599&quot; },
                      { &quot;GroupId&quot;, &quot;25&quot; },
                      { &quot;TypeId&quot;, &quot;Finance&quot; },
  
                  }
              });
  
              list.Add(new MyFiles
              {
                  Id = 2,
                  FileName = &quot;myTestfile1.jpg&quot;,
                  Metadata = new Dictionary&lt;string, string&gt;
                  {
                      { &quot;FileSize&quot;, &quot;748&quot; },
                      { &quot;GroupId&quot;, &quot;25&quot; },
                      { &quot;TypeId&quot;, &quot;HR&quot; },
  
                  }
              });
  
              list.Add(new MyFiles
              {
                  Id = 3,
                  FileName = &quot;myTestfile2.jpg&quot;,
                  Metadata = new Dictionary&lt;string, string&gt;
                  {
                      { &quot;FileSize&quot;, &quot;78&quot; },
                      { &quot;GroupId&quot;, &quot;78&quot; },
                      { &quot;TypeId&quot;, &quot;IT&quot; },
  
                  }
              });
  
              list.Add(new MyFiles
              {
                  Id = 4,
                  FileName = &quot;myTestfile2.jpg&quot;,
                  Metadata = new Dictionary&lt;string, string&gt;
                  {
                      { &quot;FileSize&quot;, &quot;783&quot; },
                      { &quot;GroupId&quot;, &quot;78&quot; },
                      { &quot;TypeId&quot;, &quot;IT&quot; },
  
                  }
              });
  
  
              // Instance one ===========================================
              var queryDictionary = new Dictionary&lt;string, string&gt;();
  
              queryDictionary.Add(&quot;GroupId&quot;, &quot;78&quot;);
              queryDictionary.Add(&quot;TypeId&quot;, &quot;IT&quot;);
  
              // Expected results would be Ids: 3 and 4
  
              // Instance two ===========================================
              queryDictionary.Clear();
  
              queryDictionary.Add(&quot;GroupId&quot;, &quot;78&quot;);
              queryDictionary.Add(&quot;FileSize&quot;, &quot;783&quot;);
  
              // Expected results would be Ids: 4
  
          }
  </code></pre>