申し訳ありませんが、このタイトルはより具体的ではありません - これを簡単に説明する方法はわかりませんでした。 多対多の関係を持つTripsとLocationはありますが、Locationsはそれらを使用するTripsについて知る必要はありません。私はこれを表現するために、これらのエンティティを作成しました:Entity Framework - 関連エンティティの熱心な読み込み
public class Trip
{
public int TripId { get; set; }
public virtual IList<TripLocation> TripLocations { get; set; }
}
public class TripLocation
{
public int TripId { get; set; }
public int LocationId { get; set; }
public virtual Location Location { get; set; }
}
public class Location
{
public int LocationId { get; set; }
// Note: Intentionally no collection of Trips
}
私はそれがTripLocationsだが、私は熱心な負荷に自分の場所をTripLocationsを得ることができない熱心な負荷への旅行を得ることができます。私は豊富な組み合わせの組み合わせを試してみました。
IQueryable<Trip> query = from trip in context
.Include(r =>r.TripLocations)
.Include(r => r.TripLocations.Select(tl => tl.Location))
select ride;
何か提案がありがとうございました!
「ride」とは何ですか? – tyron
"trip"はごめんなさい – gruve
なぜあなたのモデルに 'TripLocation'エンティティがありますか?このエンティティには、表示していない他のプロパティがありますか?それ以外の場合は、モデルからこのエンティティを削除し、 'Trip'と' Location'の間に直接多対多の関係を作成することができます。あなたの現在のモデルでは、実際には多対多の関係ではなく、2対1対多があります。 – Slauma