none
LINQ Error When using DefaultIfEmpty RRS feed

  • Question

  • I am trying to pull down the NULLS of the contacts and I am using DefaultIfEmpty to do it. But I am getting this error.

    "The method 'GroupJoin' cannot follow the method 'Join' or is not supported. Try writing the query in terms of supported methods or call the 'AsEnumerable' or 'ToList' method before calling unsupported methods."

    I am using the LINQ-to-CRM provider and querying from the CRM 2011 Web Service.

    This is the code I am using:

     

    var linqQuery = (from r in orgServiceContext.CreateQuery("opportunity")
       join a in orgServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals a["accountid"]
       join c in orgServiceContext.CreateQuery("contact") on ((EntityReference)r["new_contact"]).Id equals c["contactid"]
       where ((EntityReference)r["new_channelpartner"]).Id.Equals(new Guid("c55c2e09-a3be-e011-8b2e-00505691002b"))
       select new
       {
       OpportunityId = !r.Contains("opportunityid") ? string.Empty : r["opportunityid"],
       CustomerId = !r.Contains("customerid") ? string.Empty : ((EntityReference)r["customerid"]).Name,
       Priority = !r.Contains("opportunityratingcode") ? string.Empty : r.FormattedValues["opportunityratingcode"],
       ContactName = !r.Contains("new_contact") ? string.Empty : ((EntityReference)r["new_contact"]).Name,
       Source = !r.Contains("new_source") ? string.Empty : r["new_source"],
       CreatedOn = !r.Contains("createdon") ? string.Empty : r["createdon"],
       State = !a.Contains("address1_stateorprovince") ? string.Empty : a["address1_stateorprovince"],
       Zip = !a.Contains("address1_postalcode") ? string.Empty : a["address1_postalcode"],
       Eval = !r.Contains("new_colderevaluation") ? string.Empty : r.FormattedValues["new_colderevaluation"],
       DistributorName = !r.Contains("new_channelpartner") ? string.Empty : ((EntityReference)r["new_channelpartner"]).Name,
       ContactStreetAddress = !c.Contains("address1_line1") ? string.Empty : c["address1_line1"]
       });
    

     

    How would I go about getting rid of this error? Any help would be awesome.

    Thanks!


    Saturday, August 27, 2011 1:59 AM

Answers

  • Hi CrazyeD1583,

    Welcome!

    >>"The method 'GroupJoin' cannot follow the method 'Join' or is not supported. Try writing the query in terms of supported methods or call the 'AsEnumerable' or 'ToList' method before calling unsupported methods."

    The error indicates the provider couldn't recognize some local method.

    (from r in orgServiceContext.CreateQuery("opportunity").ToList()
      join a in orgServiceContext.CreateQuery("account").ToList() on ((EntityReference)r["accountid"]).Id equals a["accountid"]
      join c in orgServiceContext.CreateQuery("contact").ToList() on ((EntityReference)r["new_contact"]).Id equals c["contactid"]
      where ((EntityReference)r["new_channelpartner"]).Id.Equals(new Guid("c55c2e09-a3be-e011-8b2e-00505691002b"))
      select new
      { 
      });
    
    

    Please feel free to have a try, I add .ToList() method after each query.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by CrazyeD1583 Saturday, September 24, 2011 7:11 PM
    Monday, August 29, 2011 9:54 AM
    Moderator

All replies

  • Hi CrazyeD1583,

    Welcome!

    >>"The method 'GroupJoin' cannot follow the method 'Join' or is not supported. Try writing the query in terms of supported methods or call the 'AsEnumerable' or 'ToList' method before calling unsupported methods."

    The error indicates the provider couldn't recognize some local method.

    (from r in orgServiceContext.CreateQuery("opportunity").ToList()
      join a in orgServiceContext.CreateQuery("account").ToList() on ((EntityReference)r["accountid"]).Id equals a["accountid"]
      join c in orgServiceContext.CreateQuery("contact").ToList() on ((EntityReference)r["new_contact"]).Id equals c["contactid"]
      where ((EntityReference)r["new_channelpartner"]).Id.Equals(new Guid("c55c2e09-a3be-e011-8b2e-00505691002b"))
      select new
      { 
      });
    
    

    Please feel free to have a try, I add .ToList() method after each query.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by CrazyeD1583 Saturday, September 24, 2011 7:11 PM
    Monday, August 29, 2011 9:54 AM
    Moderator
  • Hi Alan,

     

    Thanks for the response. I added the ToList() and I get "The given key was not present in the dictionary." I'm checking for NULLs in the select staements so I'm not sure why I am getting that.

     

    Any ideas?

     

    Thanks!

    Monday, August 29, 2011 2:19 PM
  • Hi CrazyeD,

    Thanks for your feedback.

    My suggestion is you can just Join two Tables and select less properties to see if it works. Please feel free to let me know your feedback.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 1, 2011 7:44 AM
    Moderator
  • Did you ever figure this out.  I'm having the same problem.  The MSFT answer obviously doesn't work.
    Monday, June 29, 2015 10:54 PM