私はを取得したいParent
とその唯一のアクティブなChildren
とアクティブGrand Children
Entityframework Plusを使用して
関係
親->子供-> GrandChildren
var parent = await _dbContext.Parent
.IncludeFilter(p=>p.Children.Where(c=>c.IsActive == true))
.IncludeFilter(p=>p.Children.Select(c=>c.GrandChildren.Where(gc=>gc.IsActive ==true)))
.Where(p=>p.ParnetID == 1234)
.SingleOrDefaultAsync()
上記のクエリは機能しません。子はフィルタリングされません。非アクティブな子を含むすべての子を返します。ただし、GrandChildrenはフィルタリングされます(ただし、グランドチルドレンがSQLではなくメモリでフィルタリングされていると思います)
IncludeFilter
2回目に使用するときは、Childrenにもフィルタを含める必要があります。それ以外の場合は、フィルタリングされていないChildrenを含めます。
var parent = await _dbContext.Parent
.IncludeFilter(p=>p.Children.Where(c=>c.IsActive == true))
.IncludeFilter(p=>p.Children.Where(c=>c.IsActive == true).Select(c=>c.GrandChildren.Where(gc=>gc.IsActive ==true)))
.Where(p=>p.ParnetID == 1234)
.SingleOrDefaultAsync()
これは私が最終的に使用したものです。これは3つのSQLステートメントを作成します
var parent = await _dbContext.Parent
.IncludeFilter(p=>p.Children.Where(c=>c.IsActive == true).Select(c=>c.GrandChildren.Where(gc=>gc.IsActive ==true)))
.Where(p=>p.ParnetID == 1234)
.SingleOrDefaultAsync()