【发布时间】:2019-10-13 09:25:03
【问题描述】:
我有多个表,具有一对多关系,如链
1- 地址有邮政编码
2- 邮政表有区域 id
3-区域表有城市ID
4- 城市表有县 id
5- 县表有国家 ID
6- 并在最后一个国家/地区表中
我需要从每张表中获取街道名称、完整的邮政编码、地区名称、城市名称、县名、国家/地区名称
查询如下
var address = from add in _Database.Addresses
select add;
address.Select(x=>new AddressClass {
BuildingNameOrNumber=x.BuildingNameOrNumber,
MainStreet = x.Postcode ==null ? string.Empty: x.Postcode.StreetName,
FullPostCode = x.Postcode == null ? string.Empty :x.Postcode.FullPostcode,
AreaName = x.Postcode == null ? string.Empty : x.Postcode.Area == null ? string.Empty: x.Postcode.Area.Name,
CityName = x.Postcode == null ? string.Empty : x.Postcode.Area == null ? string.Empty : x.Postcode.Area.City == null ? string.Empty: x.Postcode.Area.City.Name,
CountyName = x.Postcode == null ? string.Empty : x.Postcode.Area == null ? string.Empty : x.Postcode.Area.City == null ? string.Empty : x.Postcode.Area.City.County == null ?string.Empty: x.Postcode.Area.City.County.Name,
CountryName= x.Postcode == null ? string.Empty : x.Postcode.Area == null ? string.Empty : x.Postcode.Area.City == null ? string.Empty : x.Postcode.Area.City.County == null ? string.Empty : x.Postcode.Area.City.County.Country == null ? string.Empty:x.Postcode.Area.City.County.Country.CountryName
})
我需要将这个多重条件替换为每个属性的一个条件
【问题讨论】:
标签: c# entity-framework linq