Book Image

WCF Multi-layer Services Development with Entity Framework - Fourth Edition

By : Mike Liu
Book Image

WCF Multi-layer Services Development with Entity Framework - Fourth Edition

By: Mike Liu

Overview of this book

Table of Contents (20 chapters)
WCF Multi-layer Services Development with Entity Framework Fourth Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Hosting the HelloWorld WCF Service
Index

Using LINQ to Entities in the data access layer


Next, we will modify the data access layer to use LINQ to Entities to retrieve and update products. We will first create GetProduct to retrieve a product from the database and then create UpdateProduct to update a product in the database.

Adding a reference to the BDO project

Now that we have the BDO project in the solution, we need to modify the data access layer project to reference it.

  1. In the Solution Explorer, right-click on the NorthwindDAL project.

  2. Select Add | Reference....

  3. Select the NorthwindBDO project from the Projects tab under Solution.

  4. Click on the OK button to add the reference to the project.

Creating GetProduct in the data access layer

We can now create the GetProduct method in the data access layer's class, ProductDAO, to use LINQ to Entities to retrieve a product from the database. Just as we did in the previous chapter, we will first create an entity DbContext object and then use LINQ to Entities to get the product from the DbContext...