我正在使用带有MVVM Concept和Enity框架的银光应用程序,并且在更新值时遇到一些麻烦。让我详细说明我的问题。我有三个表说A,B和C,其中B与A具有外键关系,C与B具有外键关系。我能够保存这些表没有任何问题。我正在使用视图绑定网格,并能够检索值以进行编辑,但无法更新对数据库的任何更改。 虽然Update收到此错误**
消息:Silverlight应用程序代码中的未处理错误:4004
类别:ManagedRuntimeError消息: System.ServiceModel.DomainServices.Client.DomainOperationException: 提交操作验证失败。请检查 EntitiesInError中每个实体的Entity.ValidationErrors以获取更多信息 信息。恩 System.ServiceModel.DomainServices.Client.OperationBase.Complete(例外 错误)en System.ServiceModel.DomainServices.Client.SubmitOperation.Complete(OperationErrorStatus errorStatus)en 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的实体Object,CVEReference是B的实体对象,AddrView是Table View的实体集,addresscollection是C的集合。我不知道哪里出错或可能是这个的原因错误。请指导我完成这个问题。 谢谢。
答案 0 :(得分:2)
错误说这是验证问题。
将dcBusinessAccountingContext.SubmitChanges();
更改为
dcBusinessAccountingContext.SubmitChanges(SubmitCallback, null);
然后你可以做一些错误检查:
private void SubmitCallback(SubmitOperation operation)
{
if (operation.HasError)
{
//check "operation.EntitiesInError" for more details.
}
}
希望这会对你有所帮助。