when using Linq-to-Sql, Visual Studio creates a DataContext class for you. I’m wondering when to instantiate this context, in one of my projects I used one DataContext instanse for about 300 CRUD commands (whole project) and it worked with a little problem which I managed to solve later, and in my recent project I have created an instance of it per CRUD command, now here’s the question, what is the best way to use DataContext? one per command or one per project? or maybe one per transaction (that I thinks is a good idea too)?
And is there any difference in speed and performance it each way?
when using Linq-to-Sql, Visual Studio creates a DataContext class for you. I’m wondering when
Share
When you keep it open too short you waste performance because instantiating a DataContext is not exactly free. It is cheap but measurable. It shows up in profiles.
When you keep it open too long you get problems too:
Here are some rules what you should never do without deep understanding: