私は、エンティティは、コード最初の規則に従い、私はEFコア2.0 ThenInclude()ナビゲーション到達できない
を行う場合//This is the father class
public partial Class Solicitud{
[InverseProperty("Solicitud")]
public virtual ICollection<Operacion> Operaciones { get; set; }
//Other properties
}
//This is the child class
public partial Class Operacion{
[JsonIgnore] //This is so when serializing we don't get a circular reference
[InverseProperty("Operaciones")]
public virtual Solicitud Solicitud { get; set; }
public virtual Practica Practica { get; set; }
//Other Properties
}
//This is the grandchild class
public partial Class Practica
{
String Nombre;
//Other Properties
}
を次のようにされている子供や孫
を持つエンティティを取得しようとしています
context.Solicitudes
.Include(w => w.Operaciones)
.Where(x => x.Profesional == profesional).OrderBy(something);
「Operaciones」コレクションを作成し、「Practica」プロパティを期待どおりにnullにしても問題ありません。
問題は、私はそこ
context.Solicitudes
.Include(w => w.Operaciones)
.ThenInclude(o => o.Practica)
.Where(x => x.Profesional == profesional);
を使用することによって、孫を取得しようとすると、それはまだOperacionesを移入するが、各OperacionのプロパティPRACTICAがnullのままで、私は次のようなメッセージ
warn: Microsoft.EntityFrameworkCore.Query[100106]
The Include operation for navigation '[w].Operaciones.Practica' is unnecessary and was ignored because the navigation is not reachable in the final query results. See https://go.microsoft.com/fwlink/?linkid=850303 for more information.
を取得生じ私は非常によく
String something = solicitud.Operaciones.ElementAt(0).Practica.Nombre;
これはバグです操作を行う可能性があるため、私には
も意味がありませんか?ネストされた選択を使用することを避ける方法はありますか?クラスはたくさんのプロパティを持ち、そのアプローチを使ってドメインモデルに変更を加えるのが難しくなるという点で、本当に大きなクラスです。
ありがとうございました。
編集:編集タイトル。
お返事ありがとうございます! Practicaは参照標準化された値を持つテーブルであり、OperacionはPracticaを使用して、特定の日に実行された外科手術の種類を言うため、私のケースでは実用的ではありません。 私はSolicitudesのリストを返すことが本当に好きです。 「Practicas」は参照表であるため、OperacionにはPracticaが1つありますが、Practicaには多くのOperacionsがあります。したがって、 .Where(p => p.Operacion.Solicitud.Profesional == profesional) は、p.Operacionは単一オブジェクトではなくICollectionとして失敗します。 –