Welcome to FoxLearn
Mostly, When we begin to develop a windows forms application we start finding a pattern,
there are some patterns: Model View Controller, Model View ViewModel, and Presentation Model.
In this video, I'll show you how to insert, update, delete data in SQL database using Model View ViewModel pattern
First, Right-click on your project, then add an ADO.NET Entity Data Model to your project.
I'll use the Northwind database for practice the demo.
if you don't have the Northwind database, you can watch the video I uploaded on how to download and install the Northwind database into SQL Server.
After you finish creating your Model, you need to rebuild the project
Next, Add a DataSource to your Model, then select the DataSource type and drag it into your form designer
If you have multiple components installed you should choose the control you want to use
You can design a simple UI that allows you to insert, update, and delete customer data in the SQL Database.
After you finish designing the form.
You need to create a Customer View Model class
Now I will explain in detail about Model View, ViewModel pattern.
The View refers to the elements that displayed by the UI.
The Model represents data from Data Access Layer or a Domain Model.
As you can see in this video, the View uses a windows forms interface, while the Model I use the Entity Framework
The ViewModel class is an abstraction of the View, or mediation between View and Model.
It passes Data between View and Model.
As you can see, I'm using a Binding Source control to interact data between a View and a Model.
The philosophy of this pattern is to separate the data, logic code and the UI presentation code by presenting an intermediate layer called ViewModel.
Next, Open your form code behind, and then add the code to handle your form.
The DataBindings will bind the datasource to the control, so when the value of the Control is changed,
the value of ViewModel is changed correspondingly, you do not need to do anything else.
Using Model View, ViewModel pattern you actually separate the UI code from the Business Code, and the UI code does not handle its states.
It just gets the values and states from ViewModel.
The ViewModel does not control View like in MVC model, so it actually decoupling pattern.
You can have multiples kind of View (Windows Forms, Web Form, Silverlight, WPF) for just one ViewModel.
You can easily change the color and border of the buttons to create a beautiful UI
Thank you for watching this video and don't forget to subscribe to my channel