Please see my other MVC article.
Leveraging Visual Studio’s ORM Tool to Create a Data Layer
Any application which interacts with a data source utilizes a data layer to perform Create, Read, Update, and Delete (CRUD) operations. Usually, this is quite an arduous tasks requiring endless maintenance to reflect changes in the data source as they occur.
However, Visual Studio provides a robust, intuitive wizard as an Object-relational mapping (ORM) tool which quickly generates the entire data layer ready for use which this article will demonstrate.
For this article, I’ll begin with a test table.
First, I will add a new ADO.NET Entity Data Model project to the solution (right-click).
When prompted, I’ll name the Model TestUser.
Next, I’ll create a new data connection and name the connection settings TestUserContext.
For the database objects and settings, I’ll select the table to expose to my application and name the Model Namespace TestUserModel.
When prompted with Security Warnings, I’ll select OK to proceed.
The wizard completes and I now have a database diagram and all the code needed for an entity model necessary to easily perform CRUD operations.
With a test record in my test table, I may now reference my entity model (TestUserContext) to find the record matching the ID, update the user’s attributes from the Html form, and update the database.