With XRM’s early bound entity, we can do a lot of things, including quite complicated LINQ Queries. However, we cannot activate or deactivate records by simply setting statecode and statuscode in the early bound entity records. To do this, we must use SetStateRequest and SetStateResponse from Microsoft.Crm.Sdk.Proxy assembly.
IOrganizationService service; new_entity record; // a record of new_entity SetStateRequest setStateReq = new SetStateRequest(); setStateReq.EntityMoniker = new EntityReference(record.LogicalName, record.Id); setStateReq.State = new OptionSetValue((int)new_entityState.InActive); setStateReq.Status = new OptionSetValue(-1); SetStateResponse response = (SetStateResponse)service.Execute(setStateReq);
Cheers – Sy