Database Reference
In-Depth Information
Figure 9-6. Our model with a single Order entity
We want to update an order using a WCF service while guaranteeing that the order we're updating has not
changed since the last time we retrieved the order. We'll show two slightly different ways to handle this. In both
approaches, we use a concurrency column, in our case, the TimeStamp column.
1.
Create a WCF Service Library by right-clicking the solution and selecting Add New Project.
Select WCF WCF Service Library. Name the project Recipe6 .
2.
Right-click the project, and select Add New Item. Select Data ADO.NET Entity Data Model.
Use the wizard to add a model with the Order table. In the Entity Framework designer,
right-click the TimeStamp property, select Properties, and set its Concurrency Mode to Fixed.
In the IService1.cs file, change the service definition as shown in Listing 9-30.
3.
Listing 9-30. Our WCF Service Contract
[ServiceContract]
public interface IService1
{
[OperationContract]
Order InsertOrder();
[OperationContract]
void UpdateOrderWithoutRetrieving(Order order);
[OperationContract]
void UpdateOrderByRetrieving(Order order);
}
In the Service1.cs file, implement the service as shown in Listing 9-31.
4.
Listing 9-31. The Implementation of Our Service Contract
public class Service1 : IService1
{
public Order InsertOrder()
{
using (var context = new EFRecipesEntities())
{
// remove previous test data
context.Database.ExecuteSqlCommand("delete from chapter9.[order]");
 
Search WWH ::




Custom Search