Ну, RetrieveMultiple является ответом здесь.
То, что я сделал сейчас, - это создал новые методы, как показано ниже, для извлечения всех данных:
Основной метод
public void RetrieveDuplicates(IOrganizationService _crmService)
{
Console.Write("Please enter entity's logical name: ");
string entityLogicalName = Console.ReadLine();
//entityLogicalName = "account";
Console.Write("Please enter duplicated column: ");
string duplicatedColumn = Console.ReadLine();
QueryExpression query = new QueryExpression(entityLogicalName)
{
ColumnSet = new ColumnSet(duplicatedColumn)
};
query.AddOrder(duplicatedColumn, 0);
var results = _crmService.RetrieveAll(query)
.GroupBy(e => e.GetAttributeValue<string>(duplicatedColumn), e => e);
foreach (var group in results)
{
var count2 = group.Count();
if (count2 > 1)
{
using (StreamWriter writer = new StreamWriter("important" + DateTime.Now.ToString("ddMMMyyyyhhmm") + ".txt"))
{
foreach (var entity in group)
{
foreach (var attribute in entity.Attributes)
{
writer.WriteLine("{0} => {1} || ", attribute.Key, attribute.Value);
}
}
}
}
}
}
Выполнить весь метод
public IEnumerable<Entity> RetrieveAll(this IOrganizationService crmService, QueryExpression query)
{
if (crmService == null)
{
throw new ArgumentNullException(nameof(crmService));
}
if (query == null)
{
throw new ArgumentNullException(nameof(query));
}
if (query.TopCount.HasValue)
{
// You cannot use paging info with a top count
var results = crmService.RetrieveMultiple(query);
foreach (var entity in results.Entities) yield return entity;
}
else
{
EntityCollection results = null;
query.PageInfo = new PagingInfo
{
PageNumber = 1
};
do
{
results = crmService.RetrieveMultiple(query);
query.PageInfo.PageNumber++;
query.PageInfo.PagingCookie = results.PagingCookie;
foreach (var entity in results.Entities) yield return entity;
} while (results?.MoreRecords != false);
}
}