Chris Duff

My feedback

  1. 114 votes
    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)

      We’ll send you updates on this idea

      Chris Duff supported this idea  · 
    • 865 votes
      Sign in
      Check!
      (thinking…)
      Reset
      or sign in with
      • facebook
      • google
        Password icon
        Signed in as (Sign out)

        We’ll send you updates on this idea

        Chris Duff commented  · 

        @Shannon - Thanks for pointing out this workaround. Unfortunately it is only useful in simple cases. It has the following problems:

        (1) It requires separate database calls which is bad for performance. Your example would result in two database calls rather than one. It's worse if it must be done N times. E.g. What if I want to query all active Blogs, loading their Posts that are Tagged with "entity-framework"? Something like (if filtered include were possible):

        var blogs = context.Blogs.Where(b => b.IsActive)
        .Include(b => b.Posts, p => p.Tags.Contains("entity-framework"))
        .ToList();

        (2) It only works at the immediate child level. E.g. What if for a Blog I want to load only active Posts and for those Posts load any Tags that start with "e"? Something like (if filtered include were possible):

        var blog = context.Blogs.Where(b => b.Id == 1)
        .Include(b => b.Posts, p => p.IsActive)
        .Include(b => b.Posts.Select(p => p.Tags), t => t.StartsWith("e"))
        .Single();

        FYI the most promising workaround I've seen for more complex scenarios appears to be EntityFramework.Filters (available via NuGet). This might involve temporarily enabling/disabling global filters targeting 'included' entities. Also note that it currently has a bug stopping it from working on entities involved in inheritance.

        https://github.com/jbogard/EntityFramework.Filters

        Chris Duff commented  · 
        Chris Duff supported this idea  · 

      Feedback and Knowledge Base