提交操作验证失败
本文关键字:失败 验证 操作 提交 | 更新日期: 2023-09-27 18:12:36
我正在使用MVVM概念和实体框架的银光应用程序,并且在更新值时遇到一些麻烦。让我详细说明我的问题。我有三个表,A B和C,其中B和A有外键关系,C和B有外键关系,我可以毫无问题地保存这些表。我使用视图来绑定网格,并能够检索值进行编辑,但无法更新对数据库的任何更改。当更新我得到这个错误**
* *消息:Silverlight Application Code: 4004中的未处理错误
分类:ManagedRuntimeError信息:System.ServiceModel.DomainServices.Client.DomainOperationException:提交操作验证失败。请检查实体。EntitiesInError中每个实体的ValidationErrors信息。在System.ServiceModel.DomainServices.Client.OperationBase.Complete(异常错误)在System.ServiceModel.DomainServices.Client.SubmitOperation.Complete (OperationErrorStatuserrorStatus)在, 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的集合。
这个错误的原因是什么?
错误提示这是验证问题。change dcBusinessAccountingContext.SubmitChanges();
to
dcBusinessAccountingContext.SubmitChanges(SubmitCallback, null);
然后你可以做一些错误检查:
private void SubmitCallback(SubmitOperation operation)
{
if (operation.HasError)
{
//check "operation.EntitiesInError" for more details.
}
}