2011-10-28 98 views
2

我正在與Silverlight應用程序一起使用MVVM Concept和Enity框架,並在更新值時遇到了一些麻煩。讓我詳細說明我的問題。我有三個表,表示A,B和C,其中B與A具有外鍵關係,C具有與B的外鍵關係。我可以將這些表保存爲無任何問題。我正在使用視圖來綁定網格,並能夠檢索要編輯的值,但無法更新對數據庫的任何更改。 雖然更新正在此錯誤**提交操作失敗驗證

消息:未處理的錯誤在Silverlight應用程序代碼:4004
類別:ManagedRuntimeError消息: System.ServiceModel.DomainServices.Client.DomainOperationException: 提交操作失敗驗證。請檢查 Entities.ValidationErrors EntitiesInError中的每個實體以獲取更多 信息。烯 System.ServiceModel.DomainServices.Client.OperationBase.Complete(例外 誤差)烯 System.ServiceModel.DomainServices.Client.SubmitOperation.Complete(OperationErrorStatus 的ErrorStatus)烯 System.ServiceModel.DomainServices.Client.DomainContext。 <> C_ DisplayClassb.b _3(對象 )

**

這裏是視圖模型類..

public void Save(object obj) 
    { 
      _currentCustomer.ModifiedBy = App.CurrentUser; 
      _currentCustomer.ModifiedDateTime = System.DateTime.Now; 

      foreach (BizFramework.Web.Model.Address address in AddressCollection.ToList()) 
      { 
       string address1 = Convert.ToString(address.Address1); 
       if (address1 != null && address1.Trim()!="") 
       {       
        CVEReference = (from addref in _currentCustomer.CustomerVendorEmployeeReferences 
            where addref.CustomerID == _currentCustomer.CustomerID 
            select addref).SingleOrDefault(); 

        BizFramework.Web.Model.Address addressExists = (from rec in CVEReference.Addresses 
                    where rec.AddressTypeID == address.AddressTypeID 
                    select rec).SingleOrDefault(); 
        if (addressExists != null) 
        { 
         address.ModifiedBy = App.CurrentUser; 
         address.ModifiedDateTime = System.DateTime.Now; 
        } 
        else 
        { 
         address.AddressGuid = System.Guid.NewGuid(); 
         address.ApplicationOwner = App.CurrentUser; 
         address.CreatedBy = App.CurrentUser; 
         address.ModifiedBy = App.CurrentUser; 
         address.CreatedDateTime = System.DateTime.Now; 
         address.ModifiedDateTime = System.DateTime.Now; 

         CVEReference.Addresses.Add(address); 
        } 

       } 
       else 
       { 
        //_currentCustomer.Addresses.Remove(address); 
        AddressCollection.Remove(address); 
        //dcBusinessAccountingContext.Addresses.Remove(address); 
       } 
      }       

     dcBusinessAccountingContext.SubmitChanges(); 
    } 

//Setting Table A from the view like this 

_currentCustomer = (from CustomerAddress in dcBusinessAccountingContext.Customers 
            where CustomerAddress.CustomerID == AddrView.CustomerID 
            select CustomerAddress).SingleOrDefault(); 

其中_currentcustomer是A的實體對象,CVEReference是B的實體對象AddrView是Table View的實體集,而addresscollection是C的集合。我不知道哪裏出錯或可能是此錯誤的原因。請通過這個問題指導我。 謝謝。

+1

您是否閱讀過錯誤信息? ***請檢查EntitiesInError中每個實體的Entity.ValidationErrors以獲取更多信息。*** – Will

回答

2

錯誤表示這是驗證問題。 改變dcBusinessAccountingContext.SubmitChanges();

dcBusinessAccountingContext.SubmitChanges(SubmitCallback, null); 

然後你就可以做一些錯誤檢查:

private void SubmitCallback(SubmitOperation operation) 
{ 
     if (operation.HasError) 
     { 
      //check "operation.EntitiesInError" for more details. 
     } 
} 

希望這會幫助你。