ASP.Net Web API showing correctly in VS but giving HTTP500

前端 未结 7 893
离开以前
离开以前 2020-12-17 04:55

after a lot of help yesterday, I came up against a known error in asp.net4 beta - I upgraded to VS2012 RC Express (4.5), and now I\'m getting an internal server error, and I

7条回答
  •  一向
    一向 (楼主)
    2020-12-17 05:03

    To resolve the error 500 issue when returning JSON with entities with virtual keyword I did the following,

        public class BookingsController : ApiController
    {
        private BookingsContext db = new BookingsContext();
    
        // GET api/Bookings
        public IEnumerable GettblCustomerBookings()
        {
            db.Configuration.ProxyCreationEnabled = false;  
            return db.tblCustomerBookings.AsEnumerable();
        }
    }
    

    It's enough to disable proxy creation (which disables lazy loading as well) for the specific circumstances where proxies are disturbing, like serialization. This disables proxy creation only for the specific context instance of db

    db.Configuration.ProxyCreationEnabled = false;
    

    http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6-loading-related-entities.aspx

    http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-1-introduction-and-model.aspx

提交回复
热议问题