How to GroupJoin from flat XDocument?
I have an XDocument with a fragment that resembles:

>     <Data>
>         <Row Id="0" ParentId="-1">
>             <!-- stuff -->
>         </Row>
>         <Row Id="1" ParentId="0">
>             <!-- stuff -->
>         </Row>
>         <Row Id="3" ParentId="1">
>             <!-- stuff -->
>         </Row>
>         <Row Id="3" ParentId="-1">
>             <!-- stuff -->
>         </Row>
>         <Row Id="4" ParentId="3">
>             <!-- stuff -->
>         </Row>
>     </Data>

Assume nesting is limited to the example above.
I want to create a data structure - `IDictionary<Parent, List<Child>>`. I can't seem to get anything to join correctly. What I have to this point is:

    // get lists of data nodes
    List<XElement> pRows = xData.Elements(XName.Get("Row"))
                                .Where(e => e.Attribute(XParentId).Value == "-1")
                                .Select(e => e)
                                .ToList();
    List<XElement> cRows = xData.Elements(XName.Get("Row"))
                                .Where(e => e.Attribute(XParentId).Value != "-1")
                                .Select(e => e)
                                .ToList();

    var dataSets = pRows.GroupJoin(cRows,
                                   p => p,
                                   c => c.Attribute(XParentId).Value,
                                   (p, children) => new {
                                     ParentID = p.Attribute(XId).Value,
                                     Children = children.Select(c => c)
                                   });

The compiler is complaining:

> The type arguments for method 
'System.Linq.Enumerable.GroupJoin<TOuter,TInner,TKey,TResult>(System.Collections.Generic.IEnumerable<TOuter>,
> System.Collections.Generic.IEnumerable<TInner>,
> System.Func<TOuter,TKey>, System.Func<TInner,TKey>,
> System.Func<TOuter,System.Collections.Generic.IEnumerable<TInner>,TResult>)'
> cannot be inferred from the usage. Try specifying the type arguments
> explicitly.

I followed a sample from [MSDN using the GroupJoin][1]. I didn't want to use 2 lists - I'd prefer to use a single list of `List<XElement>` containing all the rows.


  [1]: http://msdn.microsoft.com/en-us/library/bb534297.aspx
How to GroupJoin from flat XDocument?
===

I have an XDocument with a fragment that resembles:

>     <Data>
>         <Row Id="0" ParentId="-1">
>             <!-- stuff -->
>         </Row>
>         <Row Id="1" ParentId="0">
>             <!-- stuff -->
>         </Row>
>         <Row Id="3" ParentId="1">
>             <!-- stuff -->
>         </Row>
>         <Row Id="3" ParentId="-1">
>             <!-- stuff -->
>         </Row>
>         <Row Id="4" ParentId="3">
>             <!-- stuff -->
>         </Row>
>     </Data>

Assume nesting is limited to the example above.
I want to create a data structure - `IDictionary<Parent, List<Child>>`. I can't seem to get anything to join correctly. What I have to this point is:

    // get lists of data nodes
    List<XElement> pRows = xData.Elements(XName.Get("Row"))
                                .Where(e => e.Attribute(XParentId).Value == "-1")
                                .Select(e => e)
                                .ToList();
    List<XElement> cRows = xData.Elements(XName.Get("Row"))
                                .Where(e => e.Attribute(XParentId).Value != "-1")
                                .Select(e => e)
                                .ToList();

    var dataSets = pRows.GroupJoin(cRows,
                                   p => p,
                                   c => c.Attribute(XParentId).Value,
                                   (p, children) => new {
                                     ParentID = p.Attribute(XId).Value,
                                     Children = children.Select(c => c)
                                   });

The compiler is complaining:

> The type arguments for method 
'System.Linq.Enumerable.GroupJoin<TOuter,TInner,TKey,TResult>(System.Collections.Generic.IEnumerable<TOuter>,
> System.Collections.Generic.IEnumerable<TInner>,
> System.Func<TOuter,TKey>, System.Func<TInner,TKey>,
> System.Func<TOuter,System.Collections.Generic.IEnumerable<TInner>,TResult>)'
> cannot be inferred from the usage. Try specifying the type arguments
> explicitly.

I followed a sample from [MSDN using the GroupJoin][1]. I didn't want to use 2 lists - I'd prefer to use a single list of `List<XElement>` containing all the rows.


  [1]: http://msdn.microsoft.com/en-us/library/bb534297.aspx