This is a step by step guide to add Entity Framework to our application and create Repository Pattern to simplify data access. This tutorial written based on the database created earlier.
1. Create data model
First, we will create the data model of our database. Right click on our project > Add New Item > ADO.NET Entity Data Model > Generate from Database > Set Entities Connection to DatabaseContext.
Make sure you choose all the Tables as showed below.
You should be able to see the model diagram similar to the below if it’s done well.
2. Create an Interface for our Repository. Add New Item > Interface > Name it IRepository.cs
Paste these codes into IRepository.cs file. These codes create a generic interface contract that all our repository adhere, it’s like a contract that we provide to other developers on what our repository offer.
3. Create our Repository…
View original post 69 kelime daha