2

Is there any easy way to avoid open and close connection when using code like this :

using (Entities context = new Entities())
                {
                    returnValue = context.ExecuteStoreCommand(sqlStr, param1, param2, param3, param4, param5, param6, param7);
                    context.SaveChanges();
                    return returnValue;
                }

I have alot of code like this in diffrent methods that need to be runned in a massive database(MySQL update. It would go much faster if it did not open/close connection between each method (using/SaveChanges).

Maby I have to change the code entirely and place the context as a static member and then remove the using from all the methods? Or is there a easy setting?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Ivy
  • 2,285
  • 4
  • 24
  • 29
  • Related - http://stackoverflow.com/questions/1063730/best-way-to-initialize-an-entity-framework-context – SergeyS Jan 12 '13 at 11:16

1 Answers1

0

you should go with unit of work pattern. by using unit of work pattern you are able to create transactional calls to database.

unit of work pattern

daryal
  • 14,643
  • 4
  • 38
  • 54