I've an SQL Query:
SELECT
node.GroupName
, depth = COUNT(parent.GroupName) - 1
FROM CompanyGroup node
JOIN CompanyGroup parent ON node.LeftID BETWEEN parent.LeftID AND parent.RightID
GROUP BY node.GroupName, node.LeftID
ORDER BY node.LeftID;
I've tried converting it to LINQ myself but I'm unfamiliar with the language, after some research I've tried using Linqer but it won't convert the functions 'BETWEEN' or 'COUNT'.
The closest I've gotten so far is:
var groupModel =
from node in db.CompanyGroups
join parent in db.CompanyGroups.Where(node.LeftID > parent.LeftID && node.LeftID < parent.RightID)
orderby node.LeftID
select node.GroupName;
which doesn't work and wouldn't return the 'depth' even if it did, help please!
Edit:
The query is used to return the depth of nodes in a nested set in an order so that I can create a representation of a hierarchy; I'm following this tutorial: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ on the chapter 'Finding the Depth of the Nodes'