简体   繁体   中英

Entity framework, how to manage errors for all the application?

Hi have a WPF application that use a singleton for use the entity framework in all the application without using always the using(DbContext ctx =... )

public static MyEntityDatabase db = new MyEntityDatabase();

App.db.TableXXX.Where(...)...

But, how i can manage errors for all the application in a single event? I don't want use a try-catch on every single database request or update.

Any ideas?

You can use Application.DispatcherUnhandledException Event to do that. All you have to do is add a method name App_DispatcherUnhandledException to App class (app.xaml.cs.)

void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
    // your code here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM