For the data access layer, we will use LINQ to SQL instead of the raw ADO.NET data adapters. As you will see in the next section, we will use one LINQ statement to retrieve product information from the database, and the update LINQ statements will handle the concurrency control for us easily and reliably.
As you may recall, to use LINQ to SQL in the data access layer of our WCF service, we first need to add a LINQ to SQL model class to the project. The following steps are very similar to those described in Chapter 10. So, you can refer back to that chapter for more information and screenshots if necessary.
Northwind
database in the Server Explorer, if a connection to the database is not there.Just as in the previous chapters, this will generate a class file called Northwind.designer.cs
, which contains the data context for the Northwind
database.
This same file also contains the ProductEntity
class, which will be shared by all three layers of the WCF service. By design, LINQ to SQL includes all of the entity classes inside this same file. So if you have many entity classes, this file could be very big.
There is a standalone project, MyWCF.LINQNorthwind.BusinessEntities, in the solution. As you may recall, this is the project where we define all of the data entities for the WCF service. However, because the entity classes are all contained inside the LINQ to SQL designer class now, this project will contain no more entity classes in the solution. We will leave this project in the solution, but won't use it at all. However, if you think this is confusing, you can delete this project (and all the references to this project) from the solution.