我有一個使用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