Add Conditions filter to QueryExpression give error: FilterExpression.Conditions has no setter

Hi,

I'm trying to receive records from a dynamics crm 4.0 tabel. Receiving the records works fine. Hoever, when I add a filter (I only need some of the records), I got an error-meassage on

filter.Conditions = new ConditionExpression[] { condition };

The tooltip-text says: "The property has 'Microsoft.Crm.Sdk.Query.FilterExpression.Conditions' no setter".
Compiling results in 2 error messages: "Property or indexer 'Microsoft.Crm.Sdk.Query.FilterExpression.Conditions' cannot be assigned to -- it is read only"  and "Cannot implicitly convert type 'Microsoft.Crm.Sdk.Query.ConditionExpression[]' to 'System.Collections.ArrayList' "

Any clues?
private static BusinessEntityCollection GetCampaigns(bool toekomst)
        {

            var query = new QueryExpression();
            query.ColumnSet = new AllColumns();
            query.EntityName = EntityName.campaign.ToString();

            // Retrieve the accounts where the last name is not Cannon.
            ConditionExpression condition = new ConditionExpression();
            condition.AttributeName = "crmrow_acc_startdatetime";
            if (toekomst)
            {
                condition.Operator = ConditionOperator.OnOrAfter;
            }
            else
            {
                condition.Operator = ConditionOperator.OnOrBefore;
            }
            condition.Values = new object[] { DateTime.Now.ToShortDateString() };

            // Build the filter based on the condition.
            FilterExpression filter = new FilterExpression();
            filter.FilterOperator = LogicalOperator.And;
            filter.Conditions = new ConditionExpression[] { condition };
            
            // Set the Criteria field.
            query.Criteria = filter;

            // set request and execute it
            var request = new RetrieveMultipleRequest();
            request.Query = query;
            request.ReturnDynamicEntities = true;

            var response = (RetrieveMultipleResponse)CrmUtil.Service.Execute(request);
            return response.BusinessEntityCollection;
        }

Open in new window

Leonard4pAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
While I am certainly not the CRM expert, I believe that what you are looking for is the FilterExpression.AddCondition method:

FilterExpression.AddCondition Method (Overloaded)
http://msdn.microsoft.com/en-us/library/bb890599.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leonard4pAuthor Commented:
Thanks TheLearnedOne

The Condition filter and the FilterExpression.AddCondition Method didn't work for me, but I found a workaround, actually a very nice one.


Thanks!  

        private static BusinessEntityCollection GetCampaigns(bool toekomst)
        {
            //determine condition for xml query
            string condition = toekomst ? "next-x-years" : "last-x-years";

            //xml query: retrieve campaigns
            string fetchXml =
                string.Format(
                    @"<fetch mapping='logical'>
                    	<entity name='campaign'>
                    		<attribute name='name' />
                    		<attribute name='typecode' />
                            <order attribute='crmrow_acc_startdatetime' />
                    		<filter>
                    			<condition attribute='crmrow_acc_startdatetime' operator='{0}' value='10' />
                    		</filter>
                    	</entity>
                    </fetch>", condition);
            var response = Processor.RetrieveMultipleWithFetchXml(fetchXml);
            return response;
        }

Open in new window

0
Leonard4pAuthor Commented:
this wasn't actually the solution (my response with the fetchXML was), but thanks anyway theLearnedOne
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.