Reputation: 42
Currently I have a database design as such:
Movie
1..1-->0..* MovieRelease
1..1-->0..* Performance
I would like to write a LINQ statement to select all Movie
that have one or more performance
. This is what I came up with but it isn't working.
var instances = await GeneralModelRepository.GetQueryable<Movie>()
.Include(x => x.MovieReleases)
.ThenInclude(x => x.Performances)
.Where(x => x.MovieReleases.Any())
.Where(x => x.MovieReleases.All(x => x.Performances.Any()))
.AsNoTracking().ToListAsync();
Upvotes: 0
Views: 62
Reputation: 27282
Try the following query:
var instances = await GeneralModelRepository.GetQueryable<Movie>()
.Include(x => x.MovieReleases)
.ThenInclude(x => x.Performances)
.Where(x => x.MovieReleases.SelectMany(r => r.Performances).Any())
.AsNoTracking()
.ToListAsync();
Upvotes: 1