Linq DataContext Best Practices

What is the best way (practice) to work with a DataContext of a Linq database in C # WPF. Use global widescreen DataContext, which is used in each model viewModel or open for each transaction its own DataContext?

Based on the information about msdn and https://stackoverflow.com/a/166269/2129/ , it is recommended that you create a new DataContext for each transaction. But in my case, I would like to search for data in one viewmodel and pass it to another viewmodel to change the values. Creating a new DataContext in a changing view model results in a mismatch of the states of the objects. (The selected object in the first view of the Model does not exist in the DataContext of the second viewModel, because the object is bound to an earlier DataContext). Sequence diagram for better understanding

enter image description here

"EditViewModel" cannot edit the passed value with the new DataContext, because the object is associated with the DataContext "LookupViewModel".

DataContext. LookupViewModel editViewModel, DataContext . ( ). , viewModels DataContexts editViewModel.

DataContext DataContext - ? ?

+4
1

ViewModels DataContext, .

! - , , Ioc\DI.

, ( DAL), .

, , UnitOfWork.

, : OO:

+1

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


All Articles