Resolve Concurrency Errors on Silverlight Client with WCF RIA Services
I have a Silverlight 4 project using WCF RIA Services RTM. Most of the RIA functionality is working, but I'm having a problem with concurrency checking. The server is correctly checking concurrency and passing a DomainOperationException to the DomainDataSource.SubmittedChanges event. I'm handling that even and enumerating the EntitiesInError. I then call a Resolve on the EntityConflict. This seems to be updating the "old values" for the entities so I can then resubmit them, but the client's changes are preserved in the entity. I would rather wipe out the client's changes and make them re-do them, or maybe eventually show them what changed and let them choose which to keep. Below is a code sample of what I have so far. I found this post: http://sklementiev.blogspot.com/2010/03/wcf-ria-and-concurrency.html but it doesn't seem to work with the RIA Services RTM. Thanks.
Code Sample:
Private Sub dds_SubmittedChanges(ByVal sender As Object, ByVal e As System.Windows.Controls.SubmittedChangesEventArgs)
If e.HasError Then
If TypeOf e.Error Is DomainOperationException Then
handleDomainOperationException(sender, e, "myType")
End If
End If
End Sub
Private Sub handleDomainOperationException(ByVal sender As Object, ByVal e As SubmittedChangesEventArgs, ByVal entityType As String)
Dim dds As DomainDataSource = DirectCast(sender, DomainDataSource)
Select Case DirectCast(e.Error, DomainOperationException).Status
Case OperationErrorStatus.Conflicts
ErrorWindow.CreateNew(String.Format("Another user updated this {0} between the time that you viewed it and when you submitted your changes. Your changes have been reverted. Please make your changes again and re-submit.", entityType))
For Each ent In开发者_如何学Python e.EntitiesInError
If Not ent.EntityConflict.IsDeleted Then
'tried this, doesn't overwrite changes, just updates old fields
ent.EntityConflict.Resolve()
Else
Throw New Exception("This entity has already been deleted.")
End If
Next
e.MarkErrorAsHandled()
Case OperationErrorStatus.ValidationFailed
ErrorWindow.CreateNew("Data validation failed")
End Select
End Sub
I highly recommend you look at Yacine Khammal's Pluralsight training on dealing with concurrency conflicts which has a fantastic demo of a resolution here (paywall, but $29 a month and worth many times that). See the video called "Demo : handling validation and concurrency errors." I could not find any documentation of this being implemented in samples outside of what is presented. What makes this solution ideal is that is operates above the EF layer through changesets and allows you to identify what has changed with granularity. You can prompt the user to inform them that what was loaded and edited is different than what is on the server and let them decide if they wish to either overwrite or revert to the latest.
精彩评论