【发布时间】:2019-04-28 20:02:07
【问题描述】:
我有一个类属性如下
public class Country
{
CountryId,
CountryName,
List<State>
}
Public class State
{
StateId,
StateName,
List<City>
}
Public class City
{
CityId,
CityName
}
我有每个类的数据集,它们从数据库中提取数据如下。
CountryDS
`````````
CountryId | CountryName
1 | India
2 | China
StateDS
```````
CountryId | StateId | StateName
1 | 1 | UP
1 | 2 | MP
1 | 3 | Punjab
2 | 10 | Beijing
CityDS
``````
StateId | CityId | CityName
1 | 1 | Agra
1 | 2 | Mathura
2 | 5 | Ujjain
2 | 7 | Dewas
3 | 10 | Amritsar
现在,我想将这些数据集转换为 List<Country> 对象,不使用嵌套循环或使用 LinQ 或快速提取数据的最佳方法。
Country
--> CountryId
CountryName
State
--> StateId
StateName
City
--> CityId
CityName
【问题讨论】:
-
到目前为止你尝试了什么?
-
今天的google关键字是ORM
-
"没有嵌套循环或使用 LinQ 等" - 为什么要避免它们?
-
我已经尝试过使用嵌套循环。但是创建对象需要很长时间,因为我有数百万的记录,因为 1 个国家可能有许多州,1 个州有许多城市。所以我想如果有办法用 Linq 做到这一点。那就帮帮我吧。