Convert To Dictionary needs to have a Node<T> for key
<pre><code>public Dictionary&lt;Node&lt;T&gt;, IList&lt;Node&lt;T&gt;&gt;&gt; FlattenedMap { get; private set; }
private List&lt;Node&lt;T&gt;&gt; _dependencies; (note: these T instances have a NodeId and related ParentNodeId properties in it to work with)
</code></pre>

<p>.... more code, then:</p>

<pre><code>public void CreateFlattenedMap()
{
    var groups = _dependencies.GroupBy(d =&gt; d.ParentId); // attempt to groupy the list by ParentNodeId

    var dictionary = parentGroups.ToDictionary(d =&gt; d.Key, d =&gt; d.ToList()); // attempt to flatten out each pair of parent Node&lt;T&gt; instances with their corresponding Parent Node&lt;T&gt;.Children list

    FlattenedMap = dictionary;
}
</code></pre>

<p>I'm trying to convert the groups to a dictionary but I don't want the key to be an Id. Because my FlattenedMap has a key of Node so not sure how to do the <code>ToDictionary</code> and have the key be the d, not d.Key basically to make this assignment happy.</p>

<p>So the problem is here: <code>FlattenedMap = dictionary;</code> as the dictionary ends up being <code>&lt;int, List&lt;Node&lt;T&gt;&gt;&gt;</code> instead of what I want which is <code>&lt;Node&lt;T&gt;, List&lt;Node&lt;T&gt;&gt;</code> to satisfy how I want my dictionary formed via the property as the end result.</p>

<p>UPDATE</p>

<p>So what I've tried to do but doesn't work with my pseudo coded below is since d is type T and the dictionary really needs Node as the key, not d.Key (not T.Key) I tried to do something like this:</p>

<pre><code>var dictionary = parentGroups.ToDictionary(d =&gt; new Node&lt;T&gt;(d), d =&gt; d.ToList());
</code></pre>

<p>actually now that I think about it, the List needs to not be <code>List&lt;d&gt;</code> or <code>IList&lt;d&gt;</code> but <code>List&lt;Node&lt;T&gt;(d)&gt;</code> or list of <code>&lt;Node&lt;d&gt;&gt;</code> (remember that T is an instance of d and Node expects any instance that has implemented INode which d has for sure).</p>

<p>so really that ToDictionary is creating this:  <code>&lt;d.Key, List&lt;d&gt;&gt;</code> so you end up with <code>(&lt;int, List&lt;d&gt;)</code> which is not what my final dictionary expects.</p>

<p>somehow I need to take the d and convert it to Node on the fly in that ToDictionary so I end up with Dictionary>...hope I'm stating this right but you can get the sense of what I'm trying to say hopefully.</p>

<p><strong>UPDATE</strong></p>

<p>so tried something different in that I first converted my _dependencies to all Node instances to try to make this easier to work with or make it work in my CreateFlattenedMap()</p>

<p>Sow now, I'm trying that GroupBy on a list of IList> after I cycled the original dependencylist and converted each of them to a Node (in other words Node(d)) first.</p>

<p>So now, though same problem (and here is a more complete picture of my class for you):</p>

<pre><code>   public class Tree&lt;T&gt; where T : INode
    {
        private readonly IList&lt;T&gt; _sourceDependencies;
        private readonly List&lt;Node&lt;T&gt;&gt; _nodeDependencies;

        public Node&lt;T&gt; RootNode { get; set; }
        public Dictionary&lt;Node&lt;T&gt;, IList&lt;Node&lt;T&gt;&gt;&gt; FlattenedMap { get; private set; }

         public Tree(T rootNode, IList&lt;T&gt; dependencies )
        {
            RootNode = new Node&lt;T&gt;(rootNode); //convert the custom type to Node&lt;T&gt; first so we can work with it
            _sourceDependencies = dependencies;
            _nodeDependencies = ConvertListToNodes(_sourceDependencies);

            FlattenedMap();
        }

        private List&lt;Node&lt;T&gt;&gt; ConvertListToNodes(IList&lt;T&gt; listToConvert)
        {
            List&lt;Node&lt;T&gt;&gt; nodeList = _sourceDependencies.Select(sourceNode =&gt; new Node&lt;T&gt;(sourceNode)).ToList();
        }


       public void CreateFlattenedMap()
        {
            var parentGroups = _nodeDependencies.GroupBy(d =&gt; d.ParentNodeId);

            var dictionary = parentGroups.ToDictionary(d =&gt; new Node&lt;T&gt;(d), d =&gt; d.ToList());

            FlattenedMap = dictionary;
        }
</code></pre>
