Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i get all childs row with entity commands?
    primarykey
    data
    text
    <p>i used this SQL Command to get all child and childs of child users and i dont know how can i write it with entities?</p> <pre><code>WITH ParentUser AS ( SELECT *, 1 AS nthLevel FROM [OnlinePage].[dbo].[Users] usr1 WHERE ID = @UserID UNION ALL SELECT usr2.*, nthLevel + 1 AS nthLevel FROM ParentUser pu INNER JOIN [OnlinePage].[dbo].[Users] usr2 ON pu.ID = usr2.UserParentID ) SELECT * FROM ParentUser WHERE 1 &lt; nthLevel </code></pre> <p>and my users table is:</p> <pre><code>CREATE TABLE [dbo].[Users]( [ID] [int] IDENTITY(1,1) NOT NULL, [Username] [nvarchar](50) NOT NULL, [UserParentID] [int] NOT NULL ) </code></pre> <p>it`s something like this:</p> <pre> |--------------------------------------| |ID |Username |UserParentID | |-----|-----------|--------------------| |1 |admin |0 | |2 |reseler1 |1 | |3 |user1 |1 | |4 |reseler2 |2 | |5 |user2 |4 | |6 |user3 |5 | |--------------------------------------| </pre> <p>and if i want to get all childs of reseler1 with upper sql command i change @UserID with 2 and my result is:</p> <pre> |--------------------------------------| |ID |Username |UserParentID | |-----|-----------|--------------------| |2 |reseler1 |1 | |3 |user1 |1 | |4 |reseler2 |2 | |5 |user2 |4 | |6 |user3 |5 | |--------------------------------------| </pre> <p>now i need entity model of this sql command, i search it on google and i found something in stackoverflow(<a href="https://stackoverflow.com/questions/7753039/entity-framework-querying-child-entities">Querying child entities</a>) like down code, but not work correctly and only get one level of childs:</p> <pre><code>var query = from m in dbSet.Where(x =&gt; x.ID == 1) join s in dbSet on m.ID equals s.UserParentID into masterSlaves from ms in masterSlaves.DefaultIfEmpty() select ms; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload