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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:56:29+00:00 2026-06-12T16:56:29+00:00

Environment I am using Entity Framework 5 on Framework 4.0. (This means I am

  • 0

Environment

I am using Entity Framework 5 on Framework 4.0. (This means I am actually using EF 4.4).
As entities I use STE (Self Tracking Entities) because I am working in an N-Tier application.
We use a database driven approach because EF was introduced later in the game.

Context

I have 2 Entities that both have a navigation property to each other. (EntityA has a navigation property to EntityB, and EntityB one to EntityA).
The relation is ‘EntityA > One-TO-Many > EntityB’. When I want to load the child Entities via a LINQ expression, I need to use INCLUDE (STE => Eager Loading) because I will pass all data trough several tiers.

The code

Here is my code to call EntityA with its EntityB children.

using (var ctx = new MyEntities())
{
     var result = (from s in ctx.EntityA.Include("EntityB")
                   where s.Id = 11111
                   orderby s.TimeUpdated descending 
                   select s)
               .Take(10)
               .ToList();
     return result;
}

The error

System.StackOverflowException {Cannot evaluate expression because the
current thread is in a stack overflow state.}

There is no error when I remove the ‘INCLUDE’.
I guess the reason is straightforward. I Want to load EntityA with child records EntityB, EntityB records wants to load its parent EntityA everytime, and EntityA … I guess everyone understands the infinite loop here.

My solutions or alternatives

  • I go to my EDMX file and remove the navigation property for EntityA in EntityB. If I now want to load data about EntityA while I have an EntityB to my disposal. I need to do a separate DB request and I have 2 different objects that I have to pass on trough my tiers.
  • Avoid using include, load separately the EntityA and push it into the Navigation property of my EntityB that refers to my EntityA.

the question

Are there better alternatives or approaches to fix this in my situation ? Should I go on with one of my alternatives I proposed or not? Because I was hoping for a better and cleaner solution.

I Thank you for your time

Ian

  • 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-12T16:56:31+00:00Added an answer on June 12, 2026 at 4:56 pm

    I tried to reproduce your problem in EF 5 (Visual Studio 2012) and I don’t get any errors. Is there anything else that could cause your problem? Is it working with a simple POCO setup?

    I also wanted to note that STE’s can give you quite a headache. I have worked with STE before and now I’m really trying to avoid them. Are you sure you want to use STE?

    Instead of using STE’s you can use plain old DTO’s. You will keep your rich domain model on the server and only send the data that is necessary to the client. This way you can create tailored DTO’s with the least amount of data for each use case.

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

Sidebar

Related Questions

So I have been working on a project using Entity Framework 5 in development
We're working with Entity Framework in a Windows Azure environment and till now we
I am working on a web application project and I am using Entity Framework
I have developed an application using Entity Framework , SQL Server 2000, Visual Studio
I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First
I have an ASP.NET 4.0 application that is using Entity Framework 4.3 to connect
My situation is as follows. I'm using entity framework (4.0) in which I have
I have written a small Asp.net application using Entity Framework. A Stored Procedure accepts
I've built an MVC 2 application (ASP.net 3.5) using Entity Framework, and am doing
I'm building my application with Entity Framework (model first principle). I'm also using MS

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.