sql:
SELECT node.CategoryId,node.CategoryName,node.Description,node.Lft,node.Rgt,node.ShowOnMenu,(COUNT(parent.CategoryName) - 1) AS Level,(CASE WHEN node.Lft = node.Rgt - 1 THEN 'TRUE' ELSE 'FALSE' END) AS Leaf FROM Article_Category AS node,Article_Category AS parent WHERE node.Lft BETWEEN parent.Lft AND parent.Rgt GROUP BY node.CategoryId,node.ShowOnMenu ORDER BY node.Lft
我的linq表达式:
var list = (from node in DbContext.Categories from parent in DbContext.Categories where node.Lft >= parent.Lft && node.Lft <= parent.Rgt select new { node.CategoryId,ParentName = parent.CategoryName,} into x group x by new { x.CategoryId,x.CategoryName,x.Description,x.Lft,x.Rgt,x.ShowOnMenu,} into g orderby g.Key.Lft select new { CategoryId = g.Key.CategoryId,CategoryName = g.Key.CategoryName,Description = g.Key.Description,Lft = g.Key.Lft,Rgt = g.Key.Rgt,ShowOnMenu = g.Key.ShowOnMenu,Level = g.Count() - 1,IsLeaf = g.Key.Lft == g.Key.Rgt - 1 }).ToList();
我的问题:
> linq表达式太长,有两个’select new’表达式,我想知道如何缩短它?
> linq查询的相应扩展方法是什么?如何用Extension方法表达“from … from … where …”?
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。