4

I have the following code that works as part of a Fluent NHibernate query

session.Query<Project>()
       .Where(r=>r.IsActive)
       .FetchMany(r => r.ProjectDependencies)
       .ThenFetch(r => r.DependencyProject)
       .ThenFetch(r => r.Owner)

The above code works fine but the issue is that I want to now join and load some additional "attributes" that are joins off of the DependencyProject object besides just Owner (as above). So I want to do something like this:

session.Query<Project>()
       .Where(r=>r.IsActive)
       .FetchMany(r => r.ProjectDependencies)
       .ThenFetch(r => r.DependencyProject)
       .ThenFetch(r => r.Owner)
       .AndAlsoFetch(r=>r.Status)

Or maybe like this:

session.Query<Project>()
       .Where(r=>r.IsActive)
       .FetchMany(r => r.ProjectDependencies)
       .ThenFetch(r => r.DependencyProject)
       .ThenFetch(r => r.Owner && r.Status)

Is there anyway to do multiple fetches of properties off of an object that is already being brought in as part of a ThenFetch?

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
leora
  • 188,729
  • 360
  • 878
  • 1,366
  • **The answer**, which will at the end work for you is batch fetching, e.g. described here http://stackoverflow.com/a/20970816/1679310 – Radim Köhler Sep 13 '15 at 15:27
  • Can you clarify your comment on what I would do to batch fetch both of those properties? – leora Sep 15 '15 at 11:31

1 Answers1

-1

I can't test at the moment, so this may be way off base, but this could be a possible approach:

  var query = session.Query<Project>()
            .Where(r=>r.IsActive)
            .FetchMany(r => r.ProjectDependencies)
            .ThenFetch(r => r.DependencyProject);

  query.ThenFetch(r => r.Owner).ToFuture();
  query.ThenFetch(r => r.Status).ToFuture();

  Project project = query.ToFuture().ToList();
Richard Peterson
  • 873
  • 6
  • 15