Entity environment context as static

In a web application, would it be ok if I declare the entity framework model context as static? would that be okay? is it not recommended? What for? Thank!

+32
entity-framework
May 20 '09 at 14:15
source share
3 answers

Almost certainly not.

ObjectContexts are getting bigger and bigger as more objects are requested / stored.

Also, sharing an ObjectContext between threads, like you, is not recommended due to locking issues and undefined side effects that you will have to deal with.

I wrote advice on this topic a while ago.

Tip 18 - How to determine the lifetime of your ObjectContext

+32
May 20 '09 at 16:18
source share

This answer answers your question , therefore this one . Of course, I do not consider it static!

Rick Strahl detailed article on lifecycle management.

+6
May 20 '09 at 02:20
source share

I did this the first time I implemented an entity structure. The problem was that the whole application was receiving β€œcompleted” events, so I had to do a lot of code figuring out where the call came from.

I decided to reorganize so that each page had an instance of context. I like it now.

/my experience

+2
May 20 '09 at
source share



All Articles