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:
Northwind
database in the LINQ to Entities designerThe 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:
LINQNorthwindDAL
with solution name LINQNorthwind
(make sure the Create
directory for the solution is checked to specify the solution name).Class1.cs
file.ProductDAO
to the project.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.