How to create a simple data access layer using Repository Pattern with Entity Framework

BIZVISE

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.

Create Repository Pattern DAL using Entity Framework | SamuraiListing Example

Create Repository Pattern DAL using Entity Framework | SamuraiListing Example

Make sure you choose all the Tables as showed below.

Create Repository Pattern DAL using Entity Framework | SamuraiListing Example

You should be able to see the model diagram similar to the below if it’s done well.

Create Repository Pattern DAL using Entity Framework | SamuraiListing Example

2. Create an Interface for our Repository. Add New Item > Interface > Name it IRepository.cs

Create Repository Pattern DAL using Entity Framework | SamuraiListing Example

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

Reklamlar

MVC Sitemap Provider tutorial 2 – Breadcrumbs

Ed Spencer's Blog

Once you’ve got your sitemap correctly configured and setup, you will be looking to use some of the features of a Sitemap – for example, breadcrumbs. In this post we will start with an empty MVC3 project, and add the asp.net sitemap provider, a few controller actions and corresponding views, and we will have the provider produce some breadcrumbs for us.

Setup

Lets start from an Empty MVC3 project. Fire up Visual Studio. Create a new Asp.Net MVC3 Web application. I’m going to call mine SitemapDemo:

Create new MVC3 project

For the sake of this demonstration, I have selected an empty template and have chosen Razor as my view engine.

Now before we go any further, lets go ahead and install the NuGet package.  Select View > Other Windows and then select “Package Manager Console”:

Package Manager Console Location VS2010

This will then dock the Package Manager Console somewhere into your view. In order to add the Asp.net…

View original post 1.323 kelime daha