How to correctly use DBContext/EF in a winform application?

Viewed 3917

There is not much information about EF in winforms applications. On this msdn page, we found :

When working with Windows Presentation Foundation (WPF) or Windows Forms, use a context instance per form. This lets you use change-tracking functionality that context provides.

So I assume that I shouldn't use :

using (var context = new MyAppContext()) 
{     
    // Perform operations 
}

but I should create a new MyAppContext at loading time of each form and release it when the form is closing (and optionally SaveChange() before).

Is it correct ?

If yes, how can I change at runtime my database for my whole application ?

1 Answers
Related