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 4329094
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:46:38+00:00 2026-05-21T09:46:38+00:00

I have no idea if I’m doing this right, but this is how a

  • 0

I have no idea if I’m doing this right, but this is how a Get method in my repository looks:

    public IQueryable<User> GetUsers(IEnumerable<Expression<Func<User, object>>> eagerLoading)
    {
        IQueryable<User> query = db.Users.AsNoTracking();

        if (eagerLoading != null)
        {
            foreach (var expression in eagerLoading)
            {
                query = query.Include(expression);
            }
        }            
        return query;
    }

Lets say I also have a GeographyRepository that has GetCountries method, which is similar to this.

I have 2 separate service layer classes calling these 2 separate repositories, sharing the same DbContext (EF 4.1 code-first).

So in my controller, I’d do:

myViewModel.User = userService.GetUserById(1);
myViewModel.Countries = geoService.GetCountries();

This is 2 separate calls to the database. If I didn’t use these patterns and tie up the interface and database, I’d have 1 call. I guess its something of a performance vs maintainability.

My question is, can this be pushed to 1 database call? Can we merge queries like this when views calls multiple repositories?

  • 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-21T09:46:39+00:00Added an answer on May 21, 2026 at 9:46 am

    I’d say that if performance is the real issue then I’d try and avoid going back to the database altogether. I’m assuming the list returned from geoService.GetCountries() is fairly static, so I’d be inclined to cache it in the service after the initial load and remove the database hit altogether. The fact that you have a service there suggests that it would be the perfect place to abstract away such details.

    Generally when asking questions about performance, it’s rare that all perf related issues can be tarred with the same brush and you need to analyse each situation and work out an appropriate solution for the specific perf issue you’re having.

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

Sidebar

Related Questions

I have an idea for how to solve this problem, but I wanted to
hello im developing a blog right now... but i don't have idea how to
I have no idea why but every 5-10 times I refresh my site in
I have no idea why but my website loads slow... I suspect there is
I have this idea for a free backup application. The largest problem I need
In fact I have Idea about the exception handling. But while facing the interview
I have to find polygon overlaps and get their geometry. Does anybody have idea
I need to invoke action on a web service, but i have no idea
I got an problem, im programing an antihack program but i dont have idea
I want to use TextArea as an inputStream.Anyone have idea how this can be

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.