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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:18:24+00:00 2026-06-15T12:18:24+00:00

Performance testing on a recent project led me to redesign my models, and move

  • 0

Performance testing on a recent project led me to redesign my models, and move away from nested models. I’m going to try to detail what I was seeing in hopes that someone can correct my understanding.

I started with a Location model with a nested Address.

public class Location
{
    [Key]
    public int LocationId { get; set; }
    public string Name { get; set; }
    public int? AddressId {get;set;}
    public virtual Address Address{get;set;}
}
public class Address
{
    [Key]
    public int AddressId {get;set;}
    public string Street1 { get; set; }
    public string Street2 { get; set; }
    public string Street3 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }
}

The model was populated with LINQ in the controller (cms is my DbContext and contains DbSets for Location and Address):

public ActionResult ListLocations()
{    
    return View((from l in cms.Locations select l).ToList());
}

The view was a simple loop to display the locations in a table.

<table id="myTable" class="tablesorter">
    <thead>
        <tr>
            <th>Name</th>
            <th>City</th>
            <th>State</th>
            <th>Zip</th>
        </tr>
    </thead>
    <tbody>
        @if (Model != null)
        {
            foreach (var item in Model)
            {
            <tr>
                <td>@item.Name</td>
                <td>@item.Address.City</td>
                <td>@item.Address.State</td>
                <td>@item.Address.Zip</td>
            </tr>
            }
        }
    </tbody>
</table>

This method worked as expected, but took on average about 2000ms to complete. Each additional location that I added made the response about 120ms slower.

Using Stack Exchange’s MiniProfiler, I was able to pinpoint each 120ms delay to the first time a address was ‘retrieved’ for display. If subsequent locations had the same address, the performance cost was trivial for repeat displays. The ‘Name’ property retrieval was trivial in all cases.

It appears that the nested model is not retrieved at the same time as the parent model.

When I flattened the model by combining the properties of Address directly into Location. I was able to perform a complete request at an average of 300ms, with trivial changes to this response when adding more locations.

My question – Does Entity Framework provide a way to cache or retrieve nested models all at once or is this lazy instantiation of nested models required by convention? Is there a method for achieving similar response times in a nested model approach vs a flat model?

As always, the possibility of option c) Am I missing something obvious?

  • 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-06-15T12:18:25+00:00Added an answer on June 15, 2026 at 12:18 pm

    Try to use the Include method to include addresses in your query. Just like:

    return View((from l in cms.Locations.Include("Address") select l).ToList());
    

    http://msdn.microsoft.com/en-us/library/bb738708.aspx

    Your code is now executing a query to get the address for each location in your list. If you don´t specify what items you are getting in your query, EF does a lazy loading and each object that it needs will result in a new query.

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

Sidebar

Related Questions

For performance testing, I would like to capture some traffic from a production server
I’m doing performance testing for my application. I gathered around 100 queries from the
While doing performance testing on windows, i usually use perfmon. But when i put
I am doing some performance testing and have found that SQL seems to be
What tools for server side application performance testing you suggest? Have an application server
I have some basic questions around understanding fundamentals of Performance testing. I know that
I've just started doing some real-world performance testing on my Fluent NHibernate / SQLite
Is there any open source tool for flash performance testing.
I'm testing performance of Node.js with MongoDB. I know each of these is fine
I wrote simple load testing tool for testing performance of Java modules. One problem

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.