在多语言数据库中,我有以下表格:实体框架 - 复杂的查询最佳实践
- 区& AreaLocale:区域包含纬度/经度/ areaID表示& AreaLocale包含ID /名称/说明/ areaID表示/ CultureId
- 国家& CountryLocale:国家包含纬度/经度/ CountryId & CountryLocale包含ID /名称/说明/ CountryId/CultureId
- 文化:包含ID /名称/显示名称
现在,我需要的是找回如下:
areaID表示/名称/说明/经度/纬度/ CountryId /国家名称/ CultureId /文化显示名称,如该区域的请将isDeleted =假。
下面的查询写的是:
var q = (from areas in context.Areas
join countries in context.Countries on areas.CountryId equals countries.CountryId
join arealocales in context.AreaLocales on areas.AreaId equals arealocales.AreaId
join cultures in context.Cultures on arealocales.CultureId equals cultures.CultureId
join countrylocales in context.CountryLocales on areas.CountryId equals countrylocales.CountryId
where areas.IsDeleted == false
select new Area()
{
CountryId = areas.CountryId,
CountryName = countrylocales.Name,
CultureId = cultures.CultureId,
CultureDisplayName = cultures.DisplayName,
Description = arealocales.Description,
Id = areas.AreaId,
Latitude = areas.Latitude,
Longitude = areas.Longitude,
Name = arealocales.Name
}).ToList();
是否有书面上面的查询,而不是使用联接和使用UnionAll而不是一个更好的办法?
您是否在模型中有导航属性,例如'public ICollection AreaLocales {get;组; }'和'公共国家国家{get;组; ''在'Area'类中,等等?如果你有这些,你根本不需要任何手写连接。 –
Slauma
2012-03-24 23:40:37
事实上,我有以下内容:区域AreaLocales,区域实体Country country和国家CountryLocale List。如何实现与上述相同的目标?谢谢 – Bill 2012-03-24 23:54:40