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);Loading

Sanjay DholakiyaPosted Feb 26, 2014, 11:48 PM
I think you can use "let" keyword in you LINQ query. "Let" is useful to store sub-expression result to be used in subsequent clause. It also reduces number of joins when it converts your LINQ query into its equivalent sql query.
For more... visit below link.
http://msdn.microsoft.com/en-us/library/bb383976.aspx
- Sanjay Dholakiya
Jaganathan BantheswaranPosted Dec 24, 2013, 12:30 AM
Please give us some more details & format the question content. You have just copoied from Stackoverflow & pasted it here.