Modeling the Northwind database

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.

  1. In the Solution Explorer, right-click on the project item MyWCF.LINQNorthwind.DataAccess, select menu option Add | New Item, and then choose LINQ to SQL Classes as the Template, and enter Northwind.dbml as the Class name.
  2. After Northwind.dbml has been added to the project, add a connection to the Northwind database in the Server Explorer, if a connection to the database is not there.
  3. Then, in the Server Explorer, drag the Products table onto the Northwind.dbml design pane. Rename the entity class from Product to ProductEntity.
  4. The new column LastUpdateVersion should be in the Products table, as we added it in the previous chapter. If it is not there, add it to the table with a type of Timestamp, and recreate the entity class.

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.

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

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