nhibernate - What is the best way to filter my SQL queries to search for a certain "top" parent? -
I have a website that uses nhibernate that asks a SQL Server database in one of the following tables Columns:
ID # name - ParentId
Then there are some entries in this table:
ID name ParentId 1, " I try to run a query like this (pseudo-SQL), "3" 3, "Tim", 5
5, "Jack", 7 7, "Tom", blank
I am doing .
"Select * Like this, where 7's ISD Endend" and it will return 7 or children of children, etc. . (In this example above, all rows will be returned)
Besides what is the best way to correct this without keeping everything in the loop, since I am using nhibernate, I can add it as a function in my code, but it seems that it translates hundreds of SQL statements. I'm also curious how to do it in raw SQL too.
You can use recursive CTE in SQLServer2005 +
Entry @ intern = 7; CTA with (SELECT Id, name, ParentId FROM dbo.test45 WHERE ID = @ EDi Union Select all t.Id, t.Name, t.ParentId Join DOTAST 45T. CTC on CT.PaintID = CI D.) CAT on Demo .
Comments
Post a Comment