locked
LINQ to CRM Sample Left and Inner join RRS feed

  • Question

  • I've seen samples in the SDK that does a Left Outer/inner join separetely. Can some one give me a sample that does Left and Inner join in a single query?

    Friday, November 15, 2013 11:22 AM

All replies

  • I've never managed to do this without creating two queries or just using fetch.

    If you take the following which runs ok.

    from a in AccountSet
    join c in ContactSet
    on a.PrimaryContactId.Id equals c.ContactId
    into gr
    from c_joined in gr.DefaultIfEmpty()
    select new
    {
    contact_name = c_joined.FullName,
    account_name = a.Name
    }
    

    Then try adding a join before the account join:

    from u in SystemUserSet
    join a in AccountSet
    on u.SystemUserId equals a.OwnerId.Id
    join c in ContactSet
    on a.PrimaryContactId.Id equals c.ContactId
    into gr
    from c_joined in gr.DefaultIfEmpty()
    select new
    {
    contact_name = c_joined.FullName,
    account_name = a.Name
    }
    

    You get 'The method 'GroupJoin' cannot follow the method 'Join' or is not supported.'

    Sometimes it's easier just to go straight to fetch in these complex scenarios since it is the only query mechanism that supports all scenarios, QueryExpression and LINQ are both restrictive in comparison.

    hth,

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, November 15, 2013 12:22 PM
    Answerer