Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:15:57+00:00 2026-05-22T22:15:57+00:00

I have a parent-child relationship between Teacher and StudentReport . Each StudentReport has a

  • 0

I have a parent-child relationship between Teacher and StudentReport. Each StudentReport has a timestamp field recording when the teacher finished the report. I have a query to find all teachers who have completed one or more of their reports as of a certain number of minutes ago:

    public IList<Teacher> FindRecentlyActiveTeachers(int intervalMinutes)
    {
        if (intervalMinutes <= 0)
            throw new ArgumentException("Interval must be a positive number of minutes");

        DateTime activityCutoff = DateTime.Now.AddMinutes(-1 * intervalMinutes);

        return Session.QueryOver<Teacher>()
            .Left.JoinQueryOver<StudentReport>(t => t.StudentReports)
            .Where(r => r.FirstSaveTimestamp >= activityCutoff)
            .TransformUsing(Transformers.DistinctRootEntity)
            .List<Teacher>();
    }

This returns the correct list of teachers, but the child collection for each teacher only contains the reports that match the selection criterion. I would like the report collection of each matching teacher to contain all of the reports, not just the few reports that meet the criteria.

Is there some way I can either load the full child collection eagerly, or omit loading it in this query and rely on lazy loading it?

Update

This is the solution:

        return Session.QueryOver<Teacher>()
            .Fetch(t => t.StudentReports).Eager
            .JoinQueryOver<StudentReport>(t => t.StudentReports)
            .Where(r => r.FirstSaveTimestamp >= activityCutoff)
            .TransformUsing(Transformers.DistinctRootEntity)
            .List<Teacher>();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:15:58+00:00Added an answer on May 22, 2026 at 10:15 pm

    Use Fetch

    return Session.QueryOver<Teacher>()
        .Fetch(t => t.StudentReports)
        .Where(r => r.FirstSaveTimestamp >= activityCutoff)
        .TransformUsing(Transformers.DistinctRootEntity)
        .List<Teacher>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using parent child relationship where a parent can have children while each child has
I have a parent-child relationship between two objects. Parent :has_many :children Child :belongs_to :parent
I have a parent child relationship between 2 classes Parent @Entity @Table(name = PARENT)
HI, I have a parent - child relationship and want to query putting a
I have parent child relationship between two entities(Parent and Child). My Parent mapping is
I have a table which defines a child-parent relationship between nodes: CREATE TABLE node
I have this situation where I have a parent child relationship between two sets
I have a parent/child database relationship between the table ACCOUNT and the table USER.
Given a parent child relationship between User and FailedLogin where a user has many
I have one-to-many relationship between parent and child Java objects. The parent object uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.