I want to create a temporary table in linq query. I have searched for the solution but didn't succeeded. here "Node" is temporary table,and "Organization.TblOrganizationUnits" is table in my database. In linq, How can i create a temporary table and how can I perform different joins and union operation of the above query. my sql
query is:
string query=string.Format(@"WITH Node (OrganizationUnitId, UnitName,ParentUnitId) AS ( SELECT Organization.TblOrganizationUnits.OrganizationUnitId, Organization.TblOrganizationUnits.UnitName , Organization.TblOrganizationUnits.ParentUnitId FROM Organization.TblOrganizationUnits WHERE OrganizationUnitId ={0} UNION ALL SELECT Organization.TblOrganizationUnits.OrganizationUnitId, Organization.TblOrganizationUnits.UnitName, Organization.TblOrganizationUnits.ParentUnitId FROM Organization.TblOrganizationUnits INNER JOIN Node ON Organization.TblOrganizationUnits.ParentUnitId = Node.OrganizationUnitId ) SELECT OrganizationUnitId, UnitName,ParentUnitId FROM Node where OrganizationUnitId not in (SELECT ParentUnitId FROM Node) option (maxrecursion 0); ", OrganizationUnitId);