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

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

Question

When request by client app, Timeout occurs. I set breakpoints to check if the parameters were entered well in the controller method, and it looks fine.

Even after a while, an System.AccessViolationException occurs and my app crashes.

My Controller Code is here.

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're using EF6. try

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

// Your Code

}

because EF tries to load the reference but end up looping in that.

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