0

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

Is there any way to renew a ObjectContext for a specific entity?

(one that stayed in my application from previous request (i.e. my caching layer))

8
  • 1
    why don't you create a new instance of object context and fetch the entity from DB again?
    – daryal
    Feb 5, 2013 at 8:42
  • Did you manage your dbContext as per-request?
    – cuongle
    Feb 5, 2013 at 8:44
  • @daryal is rigth. in your scenerio, ObjectContext disposing have no meaning. Check this question: stackoverflow.com/questions/14643491/… Feb 5, 2013 at 8:47
  • What is exactly your scenario? Are you using EF behind a services layer? If so, you should create a new instance of the context for each request. Feb 5, 2013 at 10:25
  • @CuongLe I create an new instance per request, but I also save the result in an enterprise librrary cache, as I mentioned in my question
    – Elad Benda
    Feb 5, 2013 at 12:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.