我有一个使用WCF RIA Services RTM的Silverlight 4项目。大多数RIA功能正在工作,但我在并发检查方面遇到问题。服务器正确地检查并发性并将DomainOperationException传递给DomainDataSource.SubmittedChanges事件。我甚至处理,并枚举EntitiesInError。然后我在EntityConflict上调用Resolve。这似乎是更新实体的“旧值”,因此我可以重新提交它们,但客户端的更改将保留在实体中。我宁愿消灭客户的变化,让他们重新做他们,或者最终告诉他们什么改变了,让他们选择保留。以下是我迄今为止的代码示例。我发现这个帖子:http://sklementiev.blogspot.com/2010/03/wcf-ria-and-concurrency.html,但它似乎不适用于RIA服务RTM。谢谢。使用WCF RIA Services解决Silverlight客户端的并发错误
代码示例:
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 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