1

I have a asp.net web application that uses Entity Framework. The application data layer uses a method outlined by Jordan Van Gogh found here. In a nutshell, this method uses one shared objectcontext instance per http request and is disposed of using a AspNetObjectContextDisposalModule that inherits IHttpModule.

I have added another project, a few additional tables, and setup a data layer that copies (exactly) the example I described above to my application. This additional project and subsequent different data model all work perfectly. I can perform different operations using the 2 data layers with seemingly no consequences. Of course the objectsets are different in the 2 data layers as they represent different tables.

My question is this:

Is this approach a good idea? I get most of what is going on behind the scenes but both of these models use System.Data.Objects.ObjectContext. If user A performs an operation using the first data layer while simultaneously user B performs an operation using the second data layer, are there going to be problems with the "shared" objectcontext?

Thanks. And be gentle.

Edit Note: I am using different oc keys

2
  • If I'm understanding correctly, you're using a new instance per request, right? Since two users can't share one request, they should be using different context instances. Commented Oct 22, 2010 at 22:41
  • Correct. I guess I'm a little spooked because objectcontext has this singularity feeling to it. I just wanted some feedback to reassure myself I am doing this the right way. Commented Oct 22, 2010 at 22:47

1 Answer 1

1

You should be OK:

  • The object context is per http request so the context from different users will not interfere with each other
  • Each context updates different tables so they will not interfere with each other

One thing that you may have to watch out for is what happens it two users update the same data at the same time.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Shiraz. That is how I understood it as well. I just wanted some outside validation. I have a if(context.isAttached) method to handle simultaneous updates so I think I am ok in that regard. Thanks for you help.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.