locked
crmsvcutil & IQueryable & Count RRS feed

  • Question

  • I am using early bound classes generated with crmsvcutil. The generated code also has classes to represent the solutions in CRM. I am using the following query:

    IQueryable<Solution> solutionSet = xrm.SolutionSet.Where(s => s.UniqueName == uniquePublisherName);
    if (solutionSet.Count() > 0) {...}

    This compiles well but then when I call a function to which I pass xrm as an argument like in:

    .. function(XrmServiceContext xrm,...)

    I get the following error: "The method 'Count' is not supported."

    If I comment the if statement out I can get into the function. I don't know why I get this error because IQueryable<> does have a Count() function.

    Sunday, May 27, 2012 4:02 AM

Answers

  • Hi hfaun,

    Write the if condition as mentioned below:-

    var solutionSet = xrm.SolutionSet.Where(s => s.UniqueName == uniquePublisherName).AsEnumerable();
    if (solutionSet.Count > 0) {...}

    or

    if(solutionSet.ToList().Count() > 0) { ........ }

    Thanks.



    Software developer working on Asp.Net, C#, jQuery and Dynamics CRM


    • Edited by Zohaib Uddin Khan Sunday, May 27, 2012 4:13 AM
    • Marked as answer by hfaun Sunday, May 27, 2012 4:33 AM
    Sunday, May 27, 2012 4:09 AM

All replies

  • Hi hfaun,

    Write the if condition as mentioned below:-

    var solutionSet = xrm.SolutionSet.Where(s => s.UniqueName == uniquePublisherName).AsEnumerable();
    if (solutionSet.Count > 0) {...}

    or

    if(solutionSet.ToList().Count() > 0) { ........ }

    Thanks.



    Software developer working on Asp.Net, C#, jQuery and Dynamics CRM


    • Edited by Zohaib Uddin Khan Sunday, May 27, 2012 4:13 AM
    • Marked as answer by hfaun Sunday, May 27, 2012 4:33 AM
    Sunday, May 27, 2012 4:09 AM
  • Zohaib, that did the trick! Thanks. Do you happen to know why Count()/ElementAt() etc does not work?

    Sunday, May 27, 2012 4:33 AM
  • hfaun,

    Glad it worked for you. Story is about IEnumerable or Lazy binding approach. Please mark the post as Answered.

    Thanks.


    Software developer working on Asp.Net, C#, jQuery and Dynamics CRM

    Sunday, May 27, 2012 4:35 AM