Database Model in MVVM

Hello, I'm trying to learn MVVM, and I'm not sure about some of the details, mainly in the part where the data (data) models need to communicate with the VM (ViewModel).

So, I have a cool person, he has many properties (with Raiseproperty (INotifyPropertyChanged)). Now, how can I connect this class to the virtual machine, I will create a new class and name it ViewModelPerson, but basically I want a list of faces, since displaying only one person is useless, the list will be assembled from a database (SQLite) with Dapper. Now, where do I need to create an observable list, in the viewmodel or in (data)? I think in ViewModel, since I need to associate this with the view, but where do I insert the database information from it into the ViewModel ObservableCollection? I put it in a constructor such as ViewModelPersonsList Constructor, which has a request to collect all the people from SQlite DB and paste it into the list ???

I hope you understand where I do not understand the MVVM model, if something is unclear, just ask and I will try to better explain my question.

Maxim

+5
source share
2 answers

View → View Model → Business Logic → Data Layer → DB

OR

View → View Model → WCF / Web Service → Business Logic → Data Layer → DB

If your view model needs a list of Person objects, then it should call your business logic level, and your BLL will implement the necessary logic around the data level call. Your BLL returns a list, and your VM makes it viewable through binding.

Updating Person objects work the same. The VM simply calls the BLL with updated objects.

+1
source

, Sqlite, , WPF.

, ( this).

SQL Server Compact Edition, ( Sqlite as ).

, ( ) DbContext UoW.

DAL ViewModel.

, , ViewModel, TEntity, , TEntity. DAL , CRUD CollectionViewModel , .

+1

All Articles