Search code examples
c#data-access-layerentity-framework-5

context instancing in entity framework class library used by different kinds of applications


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?


Solution

  • 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).