Dynamics CRM 2011: Linq - Multiple outer joins RRS feed

  • Question

  • Hello,

    I'm new into using Linq and I need some help.
    I'm trying to write a query that create two outer joins between CRM 2011 entities. I believe it is many possible way of solving this, and I found an example that I tried to copy, but without success.

    My query tries to connect a Lead ("LeadSet") with SystemUser ("SystemUserSet") and PostCodes ("sea_postcodeSet)" by using Guids.

    Here is my code:

    The problem is that I get an error:

    System.InvalidOperationException: A 'SelectMany' operation must be preceeded by a 'Where' operation that filters by an entity ID.

    If I comment out either "SystemUserSet" or "sea_postcodeSet" the query returnes data.

    Any clue why..??


    Marius Holm Enerud

    • Edited by morris80 Tuesday, November 5, 2013 7:34 AM
    Tuesday, November 5, 2013 7:07 AM

All replies

  • Are there anyone out there that can give me a hint?


    Marius H Enerud

    Monday, November 11, 2013 1:36 PM
  • The syntax is similar to SQL in that you can only have one FROM and WHERE clause; you have multiple of each.  Take a look at the MSDN Linq Examples:

     var list_join = (from a in svcContext.AccountSet
                      join c in svcContext.ContactSet
                      on a.PrimaryContactId.Id equals c.ContactId
                      where a.Name == "Contoso Ltd" &&
                      a.Address1_Name == "Contoso Pharmaceuticals"
                      select a).ToList();
    Monday, November 11, 2013 6:28 PM
  • Thanks, Chris!

    So how would you suggest my query should look like, following your example?



    Tuesday, November 12, 2013 8:36 AM