title: C# Linq or Lambda to get Dictionary<string, List<string>> from a class
body: <p>I cannot seem to find the answer I am looking for. Hopefully someone here can help out.</p>
  
  <p>I have a class that contains setting information for some processes. Each class has a processId, taskId, and various other pieces of information not needed for my current logic.</p>
  
  <pre><code>public class ProcessSetting
  {
      public int ProcessId { get; set; }
      public int TaskId { get; set; }
  
      // Other properties not needed
  }
  </code></pre>
  
  <p>There are multiple ProcessSettings that can exist. I am pulling the data into a List. It is possible to have a processId associated with multiple TaskIds. For example:</p>
  
  <pre><code>ProcessId: 1, TaskId: 1
  ProcessId: 1, TaskId: 1
  ProcessId: 1, TaskId: 2
  ProcessId: 1, TaskId: 3
  ProcessId: 2, TaskId: 3
  ProcessId: 2, TaskId: 4
  ProcessId: 3, TaskId: 1
  </code></pre>
  
  <p>I am initially using linq to just gather the values that I need from the existing enum: (Using distinct at the end to avoid pulling in the multiple record set of ProcessId 1 and TaskId 1)</p>
  
  <pre><code>var baseSettings = (from setting in processSettings
                      select new
                                {
                                    ProcessStr = ((ProcessEnum)setting.ProcessId).ToString(),
                                    TaskStr = ((TaskEnum)setting.TaskId).ToString()
                                }).Distinct();
  </code></pre>
  
  <p>This now gives me a list with just the processId and taskId. I found some logic on here that lead me in the right direction, but isn't exactly what I need. Here is what that was:</p>
  
  <pre><code>Dictionary&lt;string, List&lt;string&gt; = baseSettings.GroupBy(x =&gt; x.ProcessStr).ToDictionary(x =&gt; x.Key, x =&gt; x.ToList());
  </code></pre>
  
  <p>However, This is incorrect. I am getting an error: </p>
  
  <blockquote>
    <p>"Cannot convert source type
    <code>System.Collections.Generic.Dictionary&lt;string,System.Generic.List{ProcessStr:string,
    TaskStr:string}&gt;&gt;</code> to target type
    <code>System.Collections.Generic.Dictionary&lt;string,System.Collections.Generic.List&lt;string&gt;&gt;</code></p>
  </blockquote>
  
  <p>I don't want a Key with a value of {ProcessStr, TaskStr}. Can anyone point me in the right direction?</p>