Adding a data access layer
We have two layers in our solution. We need to add one more layer—the data access layer. We need to query a real database to get the product information and update the database for a given product.
Creating the data access layer project
First we will create the project for the data access layer. As we did for the business logic layer, what we need to do is add a C# class library project named RealNorthwindDAL
, where
DAL stands for Data Access Layer, to the solution. Then rename the Class1.cs
to ProductDAO.cs
and modify it as follows:
Change its namespace from
RealNorthwindDAL
toMyWCFServices.
RealNorthwindDAL
.Change the class name from
Class1
toProductDAO
.Add a reference to the project,
RealNorthwindEntities
.
Now let's modify ProductDAO.cs
for our product service:
Add the following
using
statement:using MyWCFServices.RealNorthwindEntities;
Add two new methods to the
ProductDAO
class. The first method isGetProduct
, which should be as follows:public ProductEntity...