WCF Tutorial, Part 3: Create Data Access Library

01. December 2013 WCF 0

Code First Model with ADO.NET Entity Framework is used. In this way the database can be defined during the runtime. This will use our Entity Class RoomReservation which has already defined.

  • Add a new Class Library project to the solution and name it RoomReservationData.
  • Add reference to RoomReservationContracts and EntityFramework Assemblies.

    EntityFramework needed to be installed using Nuget Packager Manager
    PM> Install-Package EntityFramework

  • Create a new class called RoomReservationContext


  • RoomReservationContext class derives from the base class DbContext to act as a context for the ADO.NET Entity Framework and defines a property named RoomReservations to return a DbSet<RoomReservation>.
  • DbContext Class represents a combination of the Unit-Of-Work and Repository patterns and enables you to query a database and group together changes that will then be written back to the store as a unit. DbContext is conceptually similar to ObjectContext.
  • DbSet<TEntity> Class represents a typed entity set that is used to perform create, read, update, and delete operations. DbSet is not publicly constructible and can only be created from a DbContext instance.
  • The based constructor is called with passing the name of the SQL connection string. If the database does not exist before starting the application, it is automatically created on first use of the context.

  • Add the following connection string to the App.config


  • Add a class called RoomReservationData to provide read, write functionality


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.