asp.net mvc 4 - force singleordefault to execute -


can tell me why following code not work in api controller (mvc4)? error saying "cannot access disposed object". found in other cases there should call tolist() forces query executed. in case, i'm using singleordefault(), isn't executed on database right away?

    public httpresponsemessage getpurchaseorder(int poid)     {         purchaseorder po;         httpresponsemessage resp;          using (pmdatadatacontext database = new pmdatadatacontext())         {             po = database.purchaseorders.singleordefault(x => x.poid == poid);             if (po == null)             {                 var message = string.format("id = {0} not found", poid);                 httperror err = new httperror(message);                 resp = request.createresponse(httpstatuscode.notfound, err);                                 }             else             {                 resp = request.createresponse(httpstatuscode.ok, po);             }         }         return resp;     } 

yes, if have lazy-loaded properties in purchaseorder, when web api tries serialize object, ef try fetch data database , context needed not available.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -