Chapter 9. Applying LINQ to Entities to a WCF Service

Now that we have learned all of the features related to LINQ and LINQ to Entities, we will use them in the data access layer of a WCF service. We will create a new WCF service very similar to the one we created in the previous chapters, but in this service, we will use LINQ to Entities to connect to the Northwind database to retrieve and update a product.

In the data access layer, we will use LINQ to Entities to retrieve product information from the database and return it to the business logic layer. You will see that with LINQ to Entities, we will need only one LINQ statement to retrieve the product details from the database in the GetProduct method and we will no longer need to worry about the database connection or the actual query statement.

In this chapter, we will also learn how to update a product with LINQ to Entities in the data access layer. We will see how to apply changes of a client object to LINQ to Entities and leave all of the update work to LINQ to Entities, and will also see how to control the concurrency of updates with LINQ to Entities.

In this chapter we will cover the following:

  • Creating the solution
  • Modeling the Northwind database in the LINQ to Entities designer
  • Adding the business domain object project
  • Implementing the data access layer using LINQ to Entities
  • Adding the business logic layer
  • Adding the service interface layer
  • Implementing the test client
  • Testing the get and update operations of the WCF service
  • Testing concurrent updates with LINQ to Entities

Creating the LINQNorthwind solution

The first thing we need to do is create a test solution. In this chapter, we will start from the data access layer. Perform the following steps:

  1. Start Visual Studio.
  2. Create a new class library project LINQNorthwindDAL with solution name LINQNorthwind (make sure the Create directory for the solution is checked to specify the solution name).
  3. Delete the Class1.cs file.
  4. Add a new class ProductDAO to the project.
  5. Change the new class ProductDAO to be public.

Now you should have a new solution with the empty data access layer class. Next, we will add a model to this layer and create the business logic layer and the service interface layer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset