I am working with silver light application with MVVM Concept and Enity framework and having some trouble in updating the values. Let me elaborate my problem. I am having three tables say A, B, and C where B has the foreign key relationship with A and C has foreign key relationship with B. I could able to save these tables with out any problem. I am using a view to bind the grid and able to retrieve values for editing but unable to update any changes to the data base. While Update am getting this error **
Message: Unhandled Error in Silverlight Application Code: 4004
Category: ManagedRuntimeError Message: System.ServiceModel.DomainServices.Client.DomainOperationException: Submit operation failed validation. Please inspect Entity.ValidationErrors for each entity in EntitiesInError for more information. en System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error) en System.ServiceModel.DomainServices.Client.SubmitOperation.Complete(OperationErrorStatus errorStatus) en System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClassb.b__3(Object )
**
here is the view model class..
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();
where _currentcustomer is the A's entity Object, CVEReference is the B's entity object, AddrView is the entityset of the Table View and addresscollection is the collection of C.
What could be the reason for this error?
Error says that this is validation issue.
change dcBusinessAccountingContext.SubmitChanges();
to
dcBusinessAccountingContext.SubmitChanges(SubmitCallback, null);
Then you can do some error checking:
private void SubmitCallback(SubmitOperation operation)
{
if (operation.HasError)
{
//check "operation.EntitiesInError" for more details.
}
}