the database function is like this, i don't believe Linq supports something like this.
It recursively gets all organizationalUnit objects, puts them in the OrgUnitRec table based on the parentId column
with OrgUnitRec (id, parentId, typeCode)
as (
select id, parentOrganizationalUnitID, organizationalUnitTypeCode
from organizationalUnit
where id = @organizationalUnitId
union all
select r.id, r.parentOrganizationalUnitID, r.organizationalUnitTypeCode
from organizationalUnit r
inner join OrgUnitRec base
on base.parentId is not null and r.id = base.parentId
)
select *
from OrgUnitRec