Linq Error : Invalid 'where' condition. An entity member is invoking an invalid property or method RRS feed

  • Question

  • Hi,

    I am running Linq query in CRM2013 and throwing error : Invalid 'where' condition. An entity member is invoking an invalid property or method.

    My Code is as below;

    var conntionRecord1Id = (from connectionBase in orgServiceContext.CreateQuery("connection")
                                             where connectionBase["record1roleid"] != null
                                select connectionBase["record1id"]).Distinct();
                    var query = from opportunity in orgServiceContext.CreateQuery("opportunity")
                                where !conntionRecord1Id.Contains(opportunity["opportunityid"])
                                orderby opportunity["createdon"] ascending
                                select new
                                    Topic = opportunity.Attributes.Contains("name") == true ? opportunity["name"] : null,
                                    OpportunityId = opportunity.Attributes.Contains("opportunityid") == true ? opportunity["opportunityid"] : null,
                                    PostalCode = opportunity.Attributes.Contains("new_address_postalcode") == true ? opportunity["new_address_postalcode"] : null,

    Error throwing on second query.

    Please help


    Tuesday, May 5, 2015 8:40 AM

All replies

  • I think the problem is with this one:

    where !conntionRecord1Id.Contains(opportunity["opportunityid"])

    Try this:

    where conntionRecord1Id.Contains(opportunity["opportunityid"]) == false

    The Linq to CRM engine has some quirks like this that cause it not to support what might work with other engines.

    Tuesday, May 5, 2015 12:10 PM
  • Thanks for reply.

    I have changed as above and error is gone but filter part (contain) is not working.


    Tuesday, May 5, 2015 12:36 PM
  • Not sure I can help with that.  I might debug this code and see what data resides in the first query for conntionRecord1Id.  

    Are you trying to get a list of opportunityId's?  If so you might need to do a foreach loop on the results of conntionRecord1Id.  Something like...

    foreach(var recordid in conntionRecord1Id)


              (do something to the record...)


    Tuesday, May 5, 2015 12:42 PM