MVC: ADO.NET Entity Data Model

Please see my other MVC articles.

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.

1-MVC-4-ADO.NET-Entity-Data-Model

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.

2-MVC-4-ADO.NET-Entity-Data-Model

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.

3-MVC-4-ADO.NET-Entity-Data-Model

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.

4-MVC-4-ADO.NET-Entity-Data-Model

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.

5-MVC-4-ADO.NET-Entity-Data-Model

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s