locked
LINQ statement to Join activities and and Contacts RRS feed

  • Question

  • I am trying to write a LINQ query in VB.Net against a CRM 2011 system to retrieve contacts and all the activities associated with each contact (i.e a simple master Detail query). I found some examples in C# but when transtaled to VB.Net they are not working so I must be missing something. My statement is of the form:

    Dim ContactList = (From Contacts In _Context.ContactSet
                           Group Join Activities In _Context.ActivityPointerSet
                           On Contacts.Id Equals Activities.RegardingObjectId.Id Into AllActivities = Group
                           Where Contacts.LastName.Equals("Smith")
                           Select Contacts, AllActivities)

    what i was hoping for was a list of contacts and then for each contact a list of all aassociated activities. Howevwer, when this query is executed, it thows a 'NotSupported' exception saying:

    The 'GroupJoin' operation must be followed by a 'SelectMany' operation where the collection selector is invoking the 'DefaultIfEmpty' method.

     

    Any help would be much appreciated.

    Thanks

    Nigel

     


    Nigel T
    Thursday, September 29, 2011 8:10 AM

All replies

  • Hi

    The exception is being thrown by the Microsoft.xrm.sdl.dll - does this imply a problem in the LINQ query engine for CRM 2011?


    Nigel T
    Thursday, September 29, 2011 9:16 AM
  • It's been a little while since this question was asked, but for anyone else looking, the LINQ to CRM provider is more limited than most LINQ providers. Grouping and aggregations are not available to us.

    I have seen a couple of code example of people querying the CRM data and then using standard LINQ to query the result to allow them to group, so this is an option if grouping is required. FetchXML is an alternative for querying data that allows both grouping and aggregations.

    Kirsten

    Thursday, November 10, 2011 3:26 PM