Hi,
I use early bound LINQ to retrieve a list of incident records on synchronous PostOperation when updating specific field in incident record, i want to change a field called "new_emailApprove" for the first retrieved record , when i use context.SaveChanges() a saveChangesException occurs. I tried to use organizationService.Update() but an exception occurs which says : "EntityState must be set to null, Created (for Create message) or Changed (for Update message)" . Here is my method that implement this:
public static void GetChangeEmailCases(IOrganizationService organizationService ,ITracingService tracingService,Incident preImageCaseEntity) { svcContext serviceContext = new svcContext(organizationService); var cases = (from incident in serviceContext.IncidentSet where incident.SubjectId.Id == preImageCaseEntity.SubjectId.Id && incident.CustomerId.Id == preImageCaseEntity.CustomerId.Id && incident.StateCode == 0 orderby incident.CreatedOn descending select incident).ToList(); tracingService.Trace("cases length :" + cases.Count); if (cases.Any()) { Incident lastCase = cases.First(); tracingService.Trace(lastCase.CreatedOn.ToString()); lastCase.new_EmailApprove = true; tracingService.Trace(lastCase.Id.ToString()); serviceContext.UpdateObject(lastCase); // exception here } serviceContext.SaveChanges(); }