开发者

TELERIK ASP.NET MVC2 AJAX Error 500 internal Error, with entity Framework 4 objects

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

Here is the controller's ajax function:

   [GridAction]
    pub开发者_运维技巧lic 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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜