I need assistance in designing a proper MVVM architecture for my WPF application. This app connects to a JSON REST API for data handling and I want to avoid using quick solutions like DataGrid
with DataSet
.
I’m employing the Caliburn.Micro framework to learn clean architectural patterns. The backend API is already established, but I’m responsible for creating the entire frontend and data access layer.
In traditional methods, tracking changes with DataSet.Tables
and examining RowState
values to identify which records need to be inserted, updated, or deleted is straightforward. However, this approach does not align well with the MVVM binding patterns.
Here are a few strategies I’m considering:
- Generate backup copies of my entity collections when opening edit forms and compare these with modified collections during save operations.
- Introduce tracking properties such as
HasChanges
andIsNewRecord
in my ViewModels. - Utilize
ObservableCollection
withCollectionChanged
events to keep track of deletions.
public class CustomerViewModel : PropertyChangedBase
{
private string _name;
private bool _hasChanges;
public string Name
{
get => _name;
set
{
_name = value;
HasChanges = true;
NotifyOfPropertyChange();
}
}
public bool HasChanges
{
get => _hasChanges;
set => Set(ref _hasChanges, value);
}
}
What’s the recommended pattern for tracking changes in MVVM applications that require batch updates to the API?