【发布时间】:2011-12-17 09:42:51
【问题描述】:
我正在使用带有 MVVM 概念和实体框架的银光应用程序,并且在更新值时遇到了一些麻烦。让我详细说明我的问题。我有三个表,分别是 A、B 和 C,其中 B 与 A 具有外键关系,C 与 B 具有外键关系。我可以毫无问题地保存这些表。我正在使用视图来绑定网格并能够检索值进行编辑,但无法更新对数据库的任何更改。 虽然更新收到此错误**
消息:Silverlight 应用程序代码中出现未处理的错误:4004
类别:ManagedRuntime错误消息: System.ServiceModel.DomainServices.Client.DomainOperationException: 提交操作验证失败。请检查 EntityInError 中每个实体的 Entity.ValidationErrors 更多信息 信息。 zh System.ServiceModel.DomainServices.Client.OperationBase.Complete(异常 错误) zh System.ServiceModel.DomainServices.Client.SubmitOperation.Complete(OperationErrorStatus errorStatus) zh 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 的集合。
这个错误的原因可能是什么?
【问题讨论】:
-
您是否阅读了错误信息? 请检查 EntitiesInError 中每个实体的 Entity.ValidationErrors 以了解更多信息。
标签: c# silverlight entity-framework mvvm