Question

I've having 500 internal error when getting the ajax response.

Here is the controller's ajax function:

   [GridAction]
    public ActionResult SelectItemGridAjax(int OrderID)
    {
        return View(new GridModel(ordersRepository.GetOrderItemsTK(OrderID).ToList()));
    }

This is what the Repository sends:

   public IEnumerable<ItemsInOrder> GetOrderItemsTK(int OrderID)
    {
        using (var context = new techrundb())
        {
           var  result = (from p in context.ItemsInOrders.Include("Order").Where(i=>i.OrderID == OrderID) select p).ToList();
           return result;
        }
    }

This is the server respond:

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

There is a "circular reference" between Order and ItemsInOrder. But if I remove the Include("Order") I get an exception when the grid is enumarating the ItemsInOrder Object (on the Order reference field).

Is this error related to the circular reference ? What should I do ? Create a new object and manually replace it on the way to and back from the grid ?

Was it helpful?

Solution

I've solved this problem by creating a new list of POCO Items from the List returned from the Database. I don't think this is the best solution, and for sure not an efficient one, but it made the grid work.

Hope a better solution will come up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top