protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Begin"); if (!CanUpdate) { throw new NotSupportedException("Update not supported."); } var id = keys["ID"] as Guid?; var entityName = keys["Name"] as string; if (id == null || entityName == null) { throw new ArgumentException("Update requires the 'ID' and 'Name' to be specified as DataKeyNames.", "keys"); } var rowsAffected = 0; var updatedEventArgs = new CrmDataSourceViewUpdatedEventArgs(); try { var entity = new Entity(entityName) { Id = id.Value }; SetEntityAttributes(entity, values); _crmDataContext.Attach(entity); _crmDataContext.UpdateObject(entity); var result = _crmDataContext.SaveChanges(); if (result.HasError) { rowsAffected = 0; } else { updatedEventArgs.Entity = entity; rowsAffected = 1; } } catch (Exception e) { ADXTrace.Instance.TraceError(TraceCategory.Application, e.ToString()); updatedEventArgs.Exception = e; updatedEventArgs.ExceptionHandled = true; } ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("End: rowsAffected={0}", rowsAffected)); OnUpdated(updatedEventArgs); return(rowsAffected); }
protected virtual void OnUpdated(CrmDataSourceViewUpdatedEventArgs args) { var handler = (EventHandler <CrmDataSourceViewUpdatedEventArgs>)Events[EventUpdated]; if (handler != null) { handler(this, args); } }