When using nhibernate, how can I do ThenFetch () and then contribute to mulitple Properties / join?

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

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 problem is that I want to join and load additional “attributes” that connect to the object DependencyProjectexcept the owner (as mentioned 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 so:

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

Is there a way to make multiple selections of the properties of an object that is already being entered as part ThenFetch?

+4
source share
1 answer

, , :

  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();
-1

Source: https://habr.com/ru/post/1606055/


All Articles