سؤال

Can anyone tell me why this code doesn't work in an 2011 online plugin? What I'm trying to do is update a collection of custom entities. It throws the following error on the service.Execute(...). Another way to achieve this much appreciated...

Unexpected exception from plug-in (Execute): : System.InvalidCastException: Specified cast is not valid.

EntityCollection CustomEntitiesNeedingSync = service.RetrieveMultiple(RelevantCustomEntitiesQuery);

foreach (Entity currentCustomRecord in CustomEntitiesNeedingSync.Entities)
{
   UpdateRequest theUpdateRequest = new UpdateRequest();
   theUpdateRequest.Target = currentCustomRecord;
   service.Execute(currentCustomRecord);               
}
هل كانت مفيدة؟

المحلول

You have to execute the request - not the record.

foreach (Entity currentCustomRecord in CustomEntitiesNeedingSync.Entities)
{
   UpdateRequest theUpdateRequest = new UpdateRequest();
   theUpdateRequest.Target = currentCustomRecord;
   service.Execute(theUpdateRequest);               
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top