1

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

回答

1

我強烈建議你看看亞辛Khammal的Pluralsight的培訓上處理具有分辨率here(付費專區的一個夢幻般的演示併發衝突,但$ 29個月的,值得很多次, )。查看名爲「演示:處理驗證和併發錯誤」的視頻。除了介紹的內容外,我無法找到任何有關此類實施的文檔。這個解決方案的理想之處在於它通過變更集在EF層以上運行,並允許您確定哪些因粒度而變化。您可以提示用戶通知他們,加載和編輯的內容與服務器上的內容不同,並讓他們決定是否要覆蓋或恢復到最新內容。

相關問題