title: Linq query Group By with contains
body: <p>I have a list of the List of string that is <code>Currency Code</code>.</p>
  
  <pre><code>var currencyCode = new List&lt;string&gt;() { "USD", "SGD", "KWD", "BHD", "LYD" };
  </code></pre>
  
  <p>And i Have another complex object.</p>
  
  <pre><code> var rate = new List&lt;Rate&gt;()
   {
          new Rate() { CurrencyName = "USD (SMALL)",CurrencyCode = "USD SMALL",BranchName="Branch1"},
          new Rate() { CurrencyName = "SGD BIG",CurrencyCode = "SGD BIG",BranchName="Branch1"},
          new Rate() { CurrencyName = "KUWAIT DINAR",CurrencyCode = "KWD",BranchName="Branch1"},
          new Rate() { CurrencyName = "USD BIG (100,50)",CurrencyCode = "USD BIG",BranchName="Branch1"},
          new Rate() { CurrencyName = "USD MEDIUM (10,20)",CurrencyCode = "USD MEDIUM",BranchName="Branch1"},
    };
  </code></pre>
  
  <p>I will have the matched currency in the below list:</p>
  
  <pre><code>var matchedCurrency = from c in rate
                        where currency.Any(w =&gt; c.CurrencyCode.Contains(w))
                        select c;
  </code></pre>
  
  <p>What i wanted is that the matching currency list should be in grouped, grouped by currency code. </p>
  
  <p>I tried by the following way but it did not worked. </p>
  
  <pre><code> var Grp = rate.GroupBy(item =&gt; currency.Any(w =&gt; item.CurrencyCode.Contains(w)))
            .Select(group =&gt; new
            {
                group.Key,
                DataList = group.ToList()
             });
  </code></pre>
  
  <p>I don't get i am actually missing. I have tried by various ways. </p>
  
  <p>I know i can loop through the <code>rate</code> and push into another object. But that does not look nice   i wanted to do this by using Linq. But i could not achieve the point.</p>
  
  <p>Output will be displayed with this object:</p>
  
  <pre><code>public class CurrencyMap
  {
      public string Code { get; set; }
  
      public List&lt;Currency&gt; currency { get; set; }
  }
  public class Currency
  {
      public string CurrencyName { get; set; }
      public string CurrencyCode { get; set; }
      public string BranchName { get; set; }
  }
  enter code here
  </code></pre>
  
  <p>EDIT: </p>
  
  <p>I missed the things at first but  i also need to have the empty list if the matching code was not found in the rate. </p>
  
  <p>In Rate there is not the matching list for "BHD", "LYD". But i also need to have the empty list with the code "BHD", "LYD"</p>