internal static void UpdateDataWithEntities(Context context, IOrganizationService service, ref List <DataLine> data) { OrganizationRequestCollection retrieveMultipleRequestsCollection = new OrganizationRequestCollection( ); int firstDataIndex = 0; int dataTotalCount = data.Count; for (int i = 0; i < dataTotalCount; i++) { if (data [i].IsOk) { QueryExpression queryExpression = new QueryExpression { TopCount = 1, ColumnSet = new ColumnSet(false) }; foreach (var item in context.ColumnItems.Where(a => a.ColumnType == ColumnTypeCode.DynamicConditionExpression)) { queryExpression.Criteria.AddCondition(item.LogicalName, item.ConditionOperatorCode, data [i].LineData [context.ColumnItems.IndexOf(item)]); } retrieveMultipleRequestsCollection.Add(new RetrieveMultipleRequest( ) { Query = queryExpression }); if (retrieveMultipleRequestsCollection.Count( ) >= context.BatchSize) { ExecuteRetrieveMultiple(service, retrieveMultipleRequestsCollection, firstDataIndex, ref data); //initialisation retrieveMultipleRequestsCollection.Clear( ); firstDataIndex = i + 1; } } } if (retrieveMultipleRequestsCollection.Count != 0) { ExecuteRetrieveMultiple(service, retrieveMultipleRequestsCollection, firstDataIndex, ref data); } }