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

  • Home
  • SEARCH
  • 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 6093569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:34:31+00:00 2026-05-23T12:34:31+00:00

I created a generic repository that handles querying my entities. When I call this:

  • 0

I created a generic repository that handles querying my entities.

When I call this:

public IQueryable<TEntity> GetQuery()
        {
           return _context.Set<TEntity>().AsQueryable();
        }

I get back the entire entity including all child entities.

When I call this:

public TEntity GetById(Guid id)
        {
            return GetQuery().Where(e => e.Id == id).FirstOrDefault();
        }

I have to specify what child entities to include.

Is there a way to get back ALL child entities without having to write includes for each entity?

  • 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-23T12:34:31+00:00Added an answer on May 23, 2026 at 12:34 pm

    Lazy loading is enabled by default. This means that the collections will be loaded when you access them, not when you retrieve the parent object e.g.

    foreach (var parent in repo.GetQuery()) {
        foreach (var child in parent.Children) {
            // do something
        }
    }
    

    If you wish to eagerly load your entities you could subclass your generic repository and override the methods where you wish to use the Include lambda. Alternatively there is an Include method that accepts a string list of associations to include, which you could expose on your generic repository.

    Update:

    Not quite sure why you gave my answer -1 but as further clarification.

    You stated regarding your GetQuery() method:

    I get back the entire entity including
    all child entities.

    The child entities are lazily loaded, whether you access the collections in debug or output them on your page.

    The single query should work, with lazy loading enabled.

    And AFAIK, with lazy loading disabled, this doesn’t mean that all the collections are loaded automatically, quite the opposite, you have to explicitly load them by calling Include.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We've created a generic method like so: public TReturnType GetValue(string key) { var configurationParameter
I recently created a generic Matrix<T> class that acts as a wrapper around a
I've created a web service that uses a generic type Response<TCode, TData> and so
I've created a generic ObjectSet<T> in my generic repository. What I would like to
I am trying to create a generic base repository for my Linq2Sql entities. I'd
CodeCampServer source code contains a generic StaticFactory . I'm surmising that this is a
I'm trying to implement a Generic Repository. This is what I've got so far
I'm trying to build a generic class to work with entities from EF. This
I'm playing around with Domain Driven Development. I'm using a generic repository implementation that
So basically i have a domain object and a generic repository that can do

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.