two trees and a joint table between them : i have three tables, 2 hierarchical and 1 junction between these. 

    Teams
    id	idParent
    1	null
    2	1
    3	null
    4	null
    5	4
	
    Projects
    id	idParent
    1	null
    2	null
    3	2
    4	2
    5	null

    TeamProjects
    idTeam	idProject
    2	    2
    3	    1
    5	    5

A project always depend on at least one team, this is what teamprojects is for.

The result i'm trying to achieve : for each of the object (both teams and projects), i want to know what are the ascendant and descendant objects (id concatened)

    idObject	ascendantTeams	descendantTeam	ascendantProjects	descendantProjects
    1		                            2	                          	7, 10
    2	         1	                                                  	7
    3			                                                     	6
    4				
    5	         4                                                   	10
    6	         3			
    7	         2                                                   	8, 9
    8	         2                                  7	
    9			 2                                  7	
    10	         5			

I am trying to achieve this with a linq to entities query, but i need both CTE (for the recursive part) and (stuff-for-xml) for the concatenation part... and neither translate to linq to entities.
so i'm trying to make a view to help, but i dont manage to write the sql for it either.

how would you resolve this, either with linq to entities or sql ?