コード例 #1
0
        internal static IEnumerable <Entity> RetrieveUserViews(string entityLogicalName, List <EntityMetadata> entitiesCache, IOrganizationService service)
        {
            try
            {
                EntityMetadata currentEmd = entitiesCache.Find(e => e.LogicalName == entityLogicalName);

                QueryByAttribute qba = new QueryByAttribute
                {
                    EntityName = "userquery",
                    ColumnSet  = new ColumnSet(true)
                };

                qba.Attributes.AddRange("returnedtypecode", "querytype");
                qba.Values.AddRange(currentEmd.ObjectTypeCode.Value, 0);

                EntityCollection views = service.RetrieveMultiple(qba);

                List <Entity> viewsList = new List <Entity>();

                foreach (Entity entity in views.Entities)
                {
                    viewsList.Add(entity);
                }

                return(viewsList);
            }
            catch (Exception error)
            {
                string errorMessage = CrmExceptionHelper.GetErrorMessage(error, false);
                throw new Exception("Error while retrieving user views: " + errorMessage);
            }
        }
コード例 #2
0
        /// <summary>
        /// Retrieve the list of views for a specific entity
        /// </summary>
        /// <param name="entityDisplayName">Logical name of the entity</param>
        /// <param name="entitiesCache">Entities cache</param>
        /// <param name="service">Organization Service</param>
        /// <returns>List of views</returns>
        public static List <Entity> RetrieveViews(string entityLogicalName, List <EntityMetadata> entitiesCache, IOrganizationService service)
        {
            try
            {
                EntityMetadata currentEmd = entitiesCache.First(emd => emd.LogicalName == entityLogicalName);

                var views = service.RetrieveMultiple(new QueryExpression("savedquery")
                {
                    ColumnSet = new ColumnSet(true),
                    Criteria  = new FilterExpression
                    {
                        Conditions =
                        {
                            new ConditionExpression("returnedtypecode", ConditionOperator.Equal, currentEmd.ObjectTypeCode.Value),
                            new ConditionExpression("querytype",        ConditionOperator.NotIn, new[] { 32,2048, 8192, 32768, 131072 })
                        }
                    }
                });

                return(views.Entities.ToList());
            }
            catch (Exception error)
            {
                string errorMessage = CrmExceptionHelper.GetErrorMessage(error, false);
                throw new Exception("Error while retrieving views: " + errorMessage);
            }
        }
コード例 #3
0
        public static EntityMetadata RetrieveEntity(string logicalName, IOrganizationService oService)
        {
            try
            {
                RetrieveEntityRequest request = new RetrieveEntityRequest
                {
                    LogicalName   = logicalName,
                    EntityFilters = EntityFilters.Attributes | EntityFilters.Relationships
                };

                RetrieveEntityResponse response = (RetrieveEntityResponse)oService.Execute(request);

                return(response.EntityMetadata);
            }
            catch (Exception error)
            {
                string errorMessage = CrmExceptionHelper.GetErrorMessage(error, false);
                throw new Exception("Error while retrieving entity: " + errorMessage);
            }
        }