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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:13:08+00:00 2026-06-10T04:13:08+00:00

In my ASP.NET MVC WebApi project I have a Repository (with an Interface) that

  • 0

In my ASP.NET MVC WebApi project I have a Repository (with an Interface) that queries the DB via a simple Linq SingleOrDefault command and then outputs everything to The Controller. (EF = Database first against Oracle DB)

The Problem is that, when I turn on Lazy Loading (via the EDMX file property) the get is loading forever and there is no response. If I turn off Lazy Loading everything works fine?

Even stranger ist that when I put all the query in a console app and output everything via Console.WriteLine it works also with lazy loading?

Interface:

Public Interface IMedienRepository
    Function [Get](id As Integer) As MEDIEN
End Interface

Repository

Private db As EFEntities
Public Sub New()
    db = New EFEntities
End Sub

Public Function [Get](id As Integer) As MEDIEN Implements IMedienRepository.[Get]
    Dim _medien = db.MEDIEN.SingleOrDefault(Function(m) m.MEDIENNR = id)

    If _medien Is Nothing Then
        Throw New NotFoundException()
    End If

    Return _medien.SingleOrDefault()
End Function

Controller

Private _repository As IMedienRepository
Public Sub New()
    Me.New(New MedienRepository())
End Sub
Public Sub New(repository As IMedienRepository)
    _repository = repository
End Sub

Public Function GetValue(id As Integer) As MEDIEN
    Try            
        Return _repository.Get(id)
    Catch generatedExceptionName As NotFoundException
        Throw New HttpResponseException(New HttpResponseMessage() With { _
         .StatusCode = System.Net.HttpStatusCode.NotFound _
        })
    End Try
End Function

FYI: It isn’t working even when I put the query directly into the controller!

I would be grateful if anybody knows about this issue and could help me because I like to use the Lazy loading feature in my MVC Views.

My work around for the Moment is to turn Lazy Loading off (db.ContextOptions.LazyLoadingEnabled = False) for calls via the WebApi …

  • 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-10T04:13:09+00:00Added an answer on June 10, 2026 at 4:13 am

    Given the behavior you describe, I suspect the lazy loading is causing (for some reason) the loading of a LOT of data from the database, which takes a long time and looks like no response. Turning lazy loading off ensures that only the first “level” of your query is returned, without populating any collection properties.

    If these calls are for a WebAPI, I’m not sure you would get any real benefit from lazy loading. API calls should be very deterministic in the way they query the database and return strictly defined result sets. Writing a well-performing API is hard (just ask the StackOverlow team!) and query performance is critical.

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

Sidebar

Related Questions

I have a layered web application that I built with ASP.NET MVC 4, WebAPI
Let's say I have an ASP.NET MVC webapp that calls a repository layer, which
I'm working on a web service using ASP.NET MVC's new WebAPI that will serve
I have just upgraded my project from ASP.net MVC 4 RC to RTM, but
Problem No 1: I have started learning ASP.NET MVC. I have made a simple
I just created an ASP .NET MVC 4 WebAPI project. In looking at the
I have a question about organizing a ASP.NET MVC project. I have 3 different
I am currently working on a ASP.NET MVC 4 Web Application project that must
Is there a better way in the new ASP.net MVC 4 WebApi to handle
ASP.Net MVC Controllers have several methods of forwarding control to another controller or action.

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.