title: Using Lambda expressions with Dictionaries
body: <p>I try get data from DB and insert to Dictionary </p>
  
  <p>The data like:(column from DB) Email.Email and have (column from DB)error message Invalid email</p>
  
  <p>(column from DB)Email.Required (column from DB) error message This field is required</p>
  
  <p>I want create Dictionary looks like</p>
  
  <pre><code>Dictionary&lt;string , Dictionary&lt;string,string&gt;&gt;
  </code></pre>
  
  <p>And result be: </p>
  
  <pre><code>&lt;Email, &lt;Email, Invalid email&gt;
  &lt;Email, &lt; Required, This field is required&gt;
  </code></pre>
  
  <p>I start do:</p>
  
  <pre><code> Email = new Dictionary&lt;string, Dictionary&lt;string, string&gt;&gt;()
              {
                  {
                     data.Where(k =&gt; k.Key.Contains("Email."))
                         .Select( k =&gt; k.Key.Split(new string[] { "." }, StringSplitOptions.None)[0])
                         .FirstOrDefault(),new Dictionary&lt;string, string&gt;()
                     {
  
                         {
                           data.Where(k =&gt; k.Key.Contains("Email."))
                            .Select( k =&gt; k.Key.Split(new string[] { "." }, StringSplitOptions.None)[1])
                            .FirstOrDefault(),
                            "VALUE"
                         }
                     }
                  }
              }
  </code></pre>
  
  <p>The result I get looks like</p>
  
  <pre><code>&lt;Email,&lt;Required,value&gt;&gt;
  </code></pre>
  
  <p>but I don't success to take </p>
  
  <pre><code> &lt;Email,&lt;Email,value&gt;&gt; 
  </code></pre>
  
  <p>Edit:</p>
  
  <p>data looks like:</p>
  
  <p><a href="http://i.stack.imgur.com/9ubR2.png" rel="nofollow">value data</a></p>
  
  <p>I don't get exception because I have only one "Email" and this key I have Dictionary that I stores the value</p>
  
  <p><strong>*My solution *</strong></p>
  
  <pre><code>    Email = new Dictionary&lt;string, Dictionary&lt;string, string&gt;&gt;()
              {
                  {
                     _dataFromDB.Where(k =&gt; k.Key.Contains("Email.")).Select( k =&gt; k.Key.Split(new string[] { "." }, StringSplitOptions.None)[0]).FirstOrDefault(),
                     _dataFromDB.Where(k=&gt; k.Key.Contains("Email.")).ToDictionary( k =&gt; split(k.Key) , va =&gt; va.Value )
                  }
              }
  
  
      private string split(String key)
      {
          string[] values = key.Split(new string[] { "." },   StringSplitOptions.None);
  
          return values[1];
      }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/4Eszw.png" rel="nofollow">solution</a></p>