score:20

Accepted answer

you cant have a where inside the where, but you can use any which will return a boolean

var result = ctx.offenders
    .include(o => o.fees)
    .include(o => o.violationoffenders)
    .include(o => o.violationoffenders.select(of => of.violation))
    .where(o => o.youthnumber != "" && o.firstname != "" 
        && o.fees.any(f=> f.amount != null)) // here
    .tolist();

score:17

in .net 5 filtered include feature is added (ef core 5.0).

supported operations are: where, orderby, orderbydescending, thenby, thenbydescending, skip, and take

using (var context = new bloggingcontext())
{
    var filteredblogs = context.blogs
        .include(blog => blog.posts
            .where(post => post.blogid == 1)
            .orderbydescending(post => post.title)
            .take(5))
        .tolist();
}

msdn reference : https://docs.microsoft.com/en-us/ef/core/querying/related-data/eager


Related Query

More Query from same tag