views:

10

answers:

1

Will there be a problem of having datacontext object in a shared variable for a website (instead of instantiating it again and again). What I mean is, is the db connection opened for ever as long as datacontext is in memory?

Will there be a performance hit if I instantiate it everytime I need.

How about the same case for context object of EF

A: 

It is a bad idea to have single L2S DataContext for whole web application. DataContext is in its behavior very similar to ObjectContext. It also implements Identity Map and Unit Of Work patterns. Due to that it should never be shared in server application. For further explanation check my answer here.

Ladislav Mrnka