问题描述
我正在尝试使用LINQ,我被困在这里。我的问题是我想要检索特定方面的所有用户的计数。让我解释。这是包含样本数据的表格快照。
1001 User1 1000 Left
1002 User2 1001 Left
1003 User3 1001 Right
1004 User4 1001 Right
1005 User5 1004 Left
1006 User6 1004 Right
1007 User7 1002 Left
1008 User8 1002 Left
1009 User9 1003正确
1010 User10 1001正确
现在数据就像.. User1有4个孩子,左边1个,右边3个,User2左边有两个孩子,依此类推。
因为user2是User1的孩子,所以User2的孩子也会成为User1的孩子。所以根据上面的数据.User1左边总共有4个孩子,右边有5个孩子。如果有任何错误,可以解决问题。但我想要一些linq或sql代码来计算这些东西
1.特定ID左边的用户总数
2。特定身份证右侧的用户总数
3.儿童用户的计数,以便我可以用它来显示一棵树
这是虚拟数据,我的实际网站将包含至少20,000个数据,我必须在那里进行计算。请为我提供逻辑。
I am trying to work with LINQ and i am stuck here. My problem is i want to retrieve the count of all the users in a specific side. Let me Explain. Here is my table snapshot with sample data.
1001 User1 1000 Left
1002 User2 1001 Left
1003 User3 1001 Right
1004 User4 1001 Right
1005 User5 1004 Left
1006 User6 1004 Right
1007 User7 1002 Left
1008 User8 1002 Left
1009 User9 1003 Right
1010 User10 1001 Right
Now the data is like .. User1 has 4 childs , 1 in left side and 3 in right side , User2 has two childs both in left and so on.
Since user2 is a child of User1 so the childs of User2 will also become child of User1 . So according to above data .User1 have a total of 4 childs in left and 5 childs in right.Aplogies if any mistakes. but i want some linq or sql code to calculate these things
1. Total count of users in left of a particular ID
2. Total count of users in right of a particular ID
3. Enumeration of Child Users so that i can use it to show a tree
This is dummy data and my actual website will contain at least 20,000 of data and i have to do calculation there. Please provide me logic for this.
推荐答案
这篇关于从表中获取未直接关联的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!