Announcement

Collapse
No announcement yet.

Nested Set Linq Statement

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Nested Set Linq Statement

    verwendetes Datenbanksystem: MS SQL Server 2008


    Ich erarbeite mir gerade anhand eines Nested Set SQL Tutorials eine DB und versuche nun das lese Statement in Linq umzuwandeln, aber das sieht nicht aus wie das handelsübliche SQL. Könnte mir jemand helfen?


    Code:
    SELECT n.name,
             COUNT(*)-1 AS level
        FROM tree AS n,
             tree AS p
       WHERE n.lft BETWEEN p.lft AND p.rgt
    GROUP BY n.lft
    ORDER BY n.lft;

    Mein Ansatz:

    Code:
    var tree = from n in db.Categories
                               from p in db.Categories
                               where n.Lft >= p.Lft && n.Rgt <= p.Rgt
                               orderby n.Lft
                               select new
                                          {
                                              name = n.Name,
                                              level = ""
                                          };

    Was mir also noch fehlt ist das "COUNT(*)-1 AS level" und das "GROUP BY n.lft" und ob der rest richtig ist, ist auch die Frage

    Danke im vorraus
Working...
X