Best Usage Pattern for DataContext

What is the best model for life DataContext? Should I just create a new one when I need it (aka, function level), should I store one available in each class that will use it (class level), or do I need to create a static class with a static DataContext (app-domain level)? Are there any recommendations on this?

+3
source share
2 answers

To a large extent, you need to maintain the same data context throughout the life cycle of the operations you want to perform if you are ever going to store changes that should be .SubmitChanges()later, since otherwise you will lose these changes.

If you just request the material, then it’s fine to create them as needed, but if you want .SubmitChanges(), if you later want to, you will have to reorganize your code many times so that you can also accept the template effectively saving datacontextglobally throughout the application from the very beginning.

, . , ( , "" , , ), . .SubmitChanges() , . , datacontext , ( StateChange , , ).

, , , .

+5

, , . 15-20 .

, SO, datacontext Controller. , . .

0

Source: https://habr.com/ru/post/1696578/


All Articles