【发布时间】:2014-02-07 11:35:57
【问题描述】:
我需要使用LINQ 和SQL 查询SELECT,结果为:
ParentId Country State ChildId
1 India kerala 2
1 India TamilNamdu 3
5 Pakistan Kasagithan1 6
5 Pakistan Kasg2 7
而我的Table 是:
Id ParentId Country State
1 0 India NULL
2 1 NULL Kerala
3 1 NULL TamilNamdu
4 1 NULL Karnadaka
5 0 Pakisthan NULL
6 5 NULL Kasagithan
7 5 NULL Kasg2
8 5 NULL Afganistha
9 0 China NULL
10 9 NULL Hwuesang1
11 9 NULL sate1
12 9 NULL sate2
【问题讨论】:
-
我建议你改变你的设计。您可以假设每个
Country、State都是一个实体(表) -
我使用的父子表是单表
-
嗯,是的,但是除了带来的麻烦,还有什么好处呢?
标签: sql linq entity-framework-4 linq-to-entities self-referencing-table