如何在EF中进行递归查询? [英] How to do a recursive query in EF ?

查看:1341
本文介绍了如何在EF中进行递归查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表  Provice 结构:

Table Provice Structure:

ParentItemKey:string

ParentItemKey: string

ItemKey:string

ItemKey:string

ItemValue:string。

ItemValue:string.

void Main()
{
	var item = Provices.Where(p=>p.ItemValue == "Xi'an");
	GetItemTree(item).ToList().Dump();
}

IQueryable<Provice> GetItemTree(IQueryable<Provice> parentList)
{
	var children = Provices.Where(item=> parentList.Any(p=>p.ItemKey == item.ParentItemKey));
	return children.Union(GetItemTree(children));
}


当它运行时,linqpad崩溃了。抱歉我的英语不好。请帮助我。

When it runs, the linqpad crashed. Sorry for my poor English. Please help me.

推荐答案

我希望生成的SQL是只有一个sql语句,是否可能?
I want the generated SQL is only one sql statement, is it possible ?


这篇关于如何在EF中进行递归查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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