使用LINQ MVC的CTE递归查询 [英] CTE recursive query with linq mvc

查看:80
本文介绍了使用LINQ MVC的CTE递归查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的类别表类似于:categoryId,cat_name,parentId

我想以层级的形式从树的根(类别)到树的底部获取所有子类别,作为与linq的父子关系,并且还希望使用mvc3 EF模型结构...

i want to fetch all child categories from root(category) to the bottom of tree in hierarchical form as parent-child relation with linq and also im using mvc3 EF model structure ...

请为此提出一些解决方案...

please suggest some solution for this ...

提前感谢,米兰

推荐答案

如果要执行此操作而不必编写用于递归地为树的每个节点生成查询的函数,则应考虑采用嵌套集体系结构而不是父/子架构.这允许通过一个查询获取一个节点的所有后代.请阅读此主题的文章,以了解更多信息: http://www.sitepoint.com/hierarchical- data-database/(确保阅读全部内容.好东西要等到第二页才开始.)

if you want to do this without having to write a function to recursively generate a query for each node of the tree, you should consider moving to a nested set architecture rather than a parent/child architecture. this allows for getting a node an all descendants with one query. read this article on the subject for more information: http://www.sitepoint.com/hierarchical-data-database/ (make sure to read the whole thing. the good stuff doesn't start until the second page.)

这篇关于使用LINQ MVC的CTE递归查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆