2011-10-28 68 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. 
     } 
} 

希望这会帮助你。