ASP.NET Web API 2 ApiController.Ok() not working, causing timeout

asp.net asp.net-web-api2 c# entity-framework-6

Question

Timeout happens when a client app makes a request. I used breakpoints to see whether the arguments in the controller method were entered correctly, and everything seemed to be in order.

Even decades later, anSystem.AccessViolationException happens, my app crashes.

Here is my controller code.

namespace REST_API_EX.Controllers 
{
    public class DeliveriesController : ApiController
    {
        private DatabaseContext db = new DatabaseContext();

        [ResponseType(typeof(Delivery))]
        public async Task<IHttpActionResult> GetDeliveryByOrder_No(string Order_No)
        {
            Delivery delivery = await db.Deliveries
                .Where(d => d.Order_No == Order_No)
                .FirstAsync();
            if (delivery == null)
            {
                return NotFound();
            }
            return Ok(delivery);
        }
    }
}
1
0
6/2/2017 4:19:52 PM

Accepted Answer

since you are using EF6. try

public class DeliveriesController : ApiController{
db.Configuration.LazyLoadingEnabled = false

// Your Code

}

due to EF's attempt to load the reference, which results in a loop.

1
6/9/2017 4:44:55 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow