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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:24:42+00:00 2026-05-20T03:24:42+00:00

Here is a simple scenario to explain what I am trying to do. Say

  • 0

Here is a simple scenario to explain what I am trying to do. Say I am creating a Blogging engine, and I have 2 entities, Post and Comment, with a 1-to-many relationship between the two. In my service layer, I have a query logic to retrieve the details about a post that goes like:

Post post = new PostByIdQuery(_unitOfWork).WithPostId(5).Execute();

That line of code will execute a query that will retrieve the post entity from the database with an id value of 5. This query object is already coded and passes integration tests using a real database.

There are two business processes in which I may want to get a post by a specified ID, if I am editing a post or when I am displaying a post with its comments. This query object works fine for both scenarios, but there are performance implications when displaying a post with it’s comments since the comment list is by default lazy loaded. Thus while iterating through the comments for a post will cause multiple database hits.

Of course, if I always eager load the comments for a post, if I”m just editing a post it causes unnecessary table joins.

Thus I want to add a new method to the fluent interface that will specifies if comments should be lazy loaded or not. The question is, how do I write an integration test that checks if the comment table is eager loaded or not so this new requirement can be checked whenever unit/integration tests are run?

As far as I can tell, the Post.Comments property will show the same when accessed whether it’s eager loaded or lazy loaded, so I’m not sure how to create a test for this.


Edit: As an FYI, this is using the Code-First mechanism of EF4, thus my entities are POCOs.

  • 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-20T03:24:42+00:00Added an answer on May 20, 2026 at 3:24 am

    There’s a chance you’ll be able to cast the collection object to the more advanced EntityCollection type, and then check the IsLoaded property therein.

    Assert.IsTrue(((EntityCollection<Comment>)Post.Comments).IsLoaded);
    

    If that doesn’t work, have a look at Rowan’s answer to this question I asked a while ago. I was trying to get my code-first collection to be exposed as EntityCollection for a different reason.

    Using CreateSourceQuery in CTP4 Code First

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

Sidebar

Related Questions

Here's my scenario: I have a simple stored procedure that removes a specific set
my question is very simple. here is my scenario: i have 1 result dataset[named=resultDS
Here is a simple scenario with table characters: CharacterName GameTime Gold Live Foo 10
I am probably overlooking something really simple here but I am trying to redirect
I have small problem when trying to create many-to-many link in doctrine. I have
Here is the simple scenario that I want to apply; There is a .NET
Here is a simple scenario in C#: var intList = new List<int>(); intList.Add(4); intList.Add(7);
I have setup simple scenario to learn about databinding in XAML. After some thinking
I'm probably missing something simple here, but I can't find the answer elsewhere. I
No doubt I'm missing something really simple here but I just can't see the

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.