0

I am using the latest Entity Framework with a code-first approach to create a data access assembly that can then be used by multiple projects. Many threads on stackoverflow seem to suggest creating one context per request in an MVC web app. But I also want to use the same assembly from WinForms or console applications - what kind of approach should one use in regards to context instancing if it is to be shared between such different programs?

user1151923
  • 1,853
  • 6
  • 28
  • 44
  • Just always create one context instance per request. – John Saunders Oct 22 '12 at 17:54
  • is that a viable option even for command line apps? thought requests are a web-only thing. – user1151923 Oct 22 '12 at 18:24
  • Sorry not to be clear. Create one context per logical operation. If your program accepts command-line arguments and then just performs one operation, then you have one. If it prompts for repeated commands, then you would use one per command. It's not really rocket science. – John Saunders Oct 22 '12 at 20:15

1 Answers1

0

One context per logical operation as said by John Saunders sounds good, guess I just have to use it differently in different types of applications (such as put it in the request object for web pages and maybe pass around an instance for console apps).

user1151923
  • 1,853
  • 6
  • 28
  • 44