コード例 #1
0
        private async Task <EntitiesWithCookie <T> > GetEntitiesWithCookie(IOrganizationServiceAsync2 service, QueryExpression qe, CancellationToken token)
        {
            var response = await service.RetrieveMultipleAsync(qe, token);

            return(new EntitiesWithCookie <T>
            {
                Entities = response.Entities.Select(e => e.AsEntity <T>()),
                Cookie = response.PagingCookie,
                MoreRecords = response.MoreRecords
            });
        }
コード例 #2
0
        /// <summary>
        /// Delete all entities that are returned by the QueryExpression.
        /// </summary>
        /// <param name="service">The Service</param>
        /// <param name="qe">The query expression used to define the set of entities to delete</param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <bool> DeleteIfExistsAsync(this IOrganizationServiceAsync2 service, QueryExpression qe, CancellationToken token = default)
        {
            var exists = false;
            var idName = EntityHelper.GetIdAttributeName(qe.EntityName);

            qe.ColumnSet = new ColumnSet(idName);
            qe.NoLock    = true;
            var entities = await service.RetrieveMultipleAsync(qe, token);

            if (entities.Entities.Count > 0)
            {
                exists = true;
                await Task.WhenAll(entities.Entities.Select(e => service.DeleteAsync(qe.EntityName, e.Id)));
            }
            return(exists);
        }
コード例 #3
0
        private static async Task <bool> DeleteIfExistsInternalAsync(IOrganizationServiceAsync2 service, string logicalName, Guid id, CancellationToken token)
        {
            var exists = false;
            var idName = EntityHelper.GetIdAttributeName(logicalName);
            var qe     = new QueryExpression(logicalName)
            {
                ColumnSet = new ColumnSet(idName)
            };

            qe.WhereEqual(idName, id);
            qe.First();
            qe.NoLock = true;
            if ((await service.RetrieveMultipleAsync(qe, token)).Entities.Count > 0)
            {
                await service.DeleteAsync(logicalName, id, token);

                exists = true;
            }
            return(exists);
        }