、私は次のテーブルを持っている:Entity Frameworkの - 複雑なクエリベストプラクティス多言語データベースで
- エリア& AreaLocale:エリアは緯度/経度が含まれています/エリアID & AreaLocale含まれているID /名前/説明/エリアID/CultureId
- 国& CountryLocale:国は、緯度/経度/ CountryId & CountryLocaleは、ID /名前/説明/ CountryId/CultureId
- 文化が含まれて含まれています。ID /名前/表示名が含まれています その結果、地域のIsDeleted = falseを、
エリアID /名前/説明/経度/緯度/ CountryId /国名/ CultureId /文化の表示名:
は今、私が取得することで必要なものを次のようです。
次のクエリが書き込まれます。
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;セット; } 'と' public Country Country {get;セット; } 'Area'クラスなどでは?これらを持っていれば、手書きの結合はまったく必要ありません。 –
Slauma
実際、私は次のようなことがあります:AreaのAreaLocalesのリスト、AreaエンティティのCountryプロパティ、CountryのCountryLocaleのList。上記と同じことを達成する方法は?ありがとうございました – Bill