Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Adding conditions in service.RetrieveMultiple in c#

(0) ShareShare
ReportReport
Posted on by

Hi ,

I am using service.RetrieveMultiple for retrieve data.

Code:

quotequery = new QueryExpression()
{
    Distinct = false,
    EntityName = modulename,
    ColumnSet = new ColumnSet(true),
    Criteria =
    {
        Filters = 
        {
            new FilterExpression
            {
                FilterOperator = LogicalOperator.And,
                Conditions = 
                {
                    new ConditionExpression("ownerid", ConditionOperator.Equal, userid),                                
                    new ConditionExpression(contactfield, ConditionOperator.Equal, lstcredential.Contactid.ToString())                                                  
                },
            }           
        }
    }
};
 queryentityCollection = _serviceProxy.RetrieveMultiple(quotequery).Entities;


i have above common function which has different different conditions at different different call so there is possibility to use some variable or something which stores conditions ans pass it in conditions={ }  like I use  modulename which stores entityname?or any other way?

Please suggest answer.

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Adding conditions in service.RetrieveMultiple in c#

    Hi Aiden and Guido , Thank You so much for your reply and time. both of your's answer are helpful. and I got success .Again Thank you.

  • Aiden Kaskela Profile Picture
    19,694 on at
    RE: Adding conditions in service.RetrieveMultiple in c#

    Guido,

    It doesn't matter if the code is inline or broken out as in your example. The specific method he's working in will need to accept the conditions and add them to the collection. There's are easier ways to accommodate that than to rewrite the query expression instantiation.

    Aiden

  • Suggested answer
    Aiden Kaskela Profile Picture
    19,694 on at
    RE: Adding conditions in service.RetrieveMultiple in c#

    Hi,

    I don't quite follow. Are you trying you update your code so you can take in the conditions as a parameter or a variable? If that's what you're after, it's a programming question. Your specific implementation is up to you and depends on how much flexibility you want the caller to have. You could do something as simple as:

    protected EntityCollection ExecuteQuery(ConditionExpression[] conditions)
    {
      // all your existing code...
      Conditions = conditions
      // the rest of the statement
      return proxy.RetrieveMultiple( {....} );
    }
    


    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

      Aiden

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans