Compartilhar via


How to: Enable Optimistic Concurrency Checks

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

This topic describes various ways to apply the RoundtripOriginalAttribute checks on entities or entity properties in WCF RIA Services to enable optimistic concurrency checking on those entities or types. For context on this procedure, see Managing Data Concurrency.

The procedure described in this topic assumes that you have a RIA Services application created. The procedures for doing this can be followed in the Walkthrough: Creating a RIA Services Solution topic.

Apply the RoundtripOriginalAttribute on Metadata classes

  1. Open the .metadata.cs file associated with the domain service.

  2. Apply the RoundtripOriginalAttribute to the properties whose values need to be checked when submitting changes to the data store, or to an entire class if you want to check the values of all of the properties contained within the class when submitting changes.

  3. Build (Ctrl+Shift+B) the application.

  4. Click the Show All Files icon in the Solution Explorer to unhide the Generated_code folder in the client project and open the .Web.g.cs file.

  5. Locate the properties and classes to which you applied the RoundtripOriginalAttribute and confirm that the attribute has been correctly generated.

  6. Note that the properties marked with the KeyAttribute in the metadata also have their corresponding client properties marked with the RoundtripOriginalAttribute.

Using the Designer to Specify Optimistic Concurrency

  1. Open the Designer and select a property in one of the entity classes whose value you want checked when submitting changes to the database.

  2. Go to the Properties window and change the value of the ConcurrencyMode from None to Fixed on the dropdown window.

  3. Build (Ctrl+Shift+B) the application.

  4. Locate the properties that have the new concurrency mode and confirm that they have had the RoundtripOriginalAttribute applied to them. Note that they have also had the ConcurrencyCheckAttribute applied to them.

  5. Go back to the Properties window and note that the key entities also a StoreGeneratedPattern set to Identity. This means that their values will be assumed to be unchanged when submitting changes for their entities and the data server value will be used.