排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术
分类:
.NET
List<Entity> list = new List<Entity> { new Entity(){ Id = 1, Name="根",Pid = 0 }, new Entity(){ Id = 2, Name="木",Pid = 1 }, new Entity(){ Id = 3, Name="铁",Pid = 1 }, new Entity(){ Id = 4, Name="金",Pid = 1 }, new Entity(){ Id = 5, Name="木剑",Pid = 2 }, new Entity(){ Id = 6, Name="木棍",Pid = 2 }, new Entity(){ Id = 7, Name="铁棒",Pid = 3 }, new Entity(){ Id = 8, Name="铁枪",Pid = 3 } }; var l = from t in list let pp = (from p in list.Select(s => s.Pid) select p) where !pp.Contains(t.Id) select t;
sql:
SELECT * FROM tree where id not in( SELECT Pid from tree)
把所有的父级id找出来,然后id不在父级id的就是最后一级
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
评价