web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Issue with making Left Out Join between Account and Campaign Enity

(0) ShareShare
ReportReport
Posted on by

Please see below my LINQ query :

var customertList = (from c in context.ContactSet
                                          join co in context.ConnectionSet on c.ContactId.Value equals co.Record1Id.Id
                                          join ac in context.AccountSet on co.Record2Id.Id equals ac.AccountId.Value
                                          join cr in context.ConnectionRoleSet on co.Record2RoleId.Id equals cr.ConnectionRoleId.Value
                                           where c.StatusCode.Value == (int)contact_statuscode.Active                                          
                                          from subca in context.CampaignSet.Where(camp => ac.AccountId.Value == camp.exch_CampaignAccount.Id).DefaultIfEmpty()                                          
                                          select new HCRCustomerRequest
                                          {
                                              FullName = c.FullName,
                                              CustomerId = c.ContactId.Value,
                                              CampaignId = subca.CampaignId.Value
                                          }).ToList()

Above query giving me error : A 'SelectMany' operation must be preceeded by a 'Where' operation that filters by an entity ID.

Please suggest what changes needed in the query to run it successfully.

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ThomasN Profile Picture
    3,190 on at

    Hi Shubh12, thanks for reaching out.

    May need more detail, but the first thing I notice is in your "from" statement the "Where" is not standing alone. It is looking "in context.CampaignSet.Where(...   Should this be changed to context.CampaignSet Where(...

    Also you might be missing "into subca" at the end of Where c.StatusCode.Value == (int)contact_statuscode.Active .

    Take a look at the Left Join 8 sample here. msdn.microsoft.com/.../gg334593.aspx

  • Community Member Profile Picture
    on at

    Hi Tom,

    Thanks for replying. Actually my problem is , I have a linq query with multiple entity/table joined, I wan to implement left join between account and campaign. When I run my linq query like following works fine for me.

    var leftJoinAccountCampaign = (from a in context.AccountSet

                   join c in context.CampaignSet

                   on a.AccountId equals c.exch_CampaignAccount.Id

                   into gr

                   from cjoined in gr.DefaultIfEmpty()

                   select new

                   {

                       camp_name = cjoined.Name,

                       account_name = a.Name

                   }).ToList();

              Sample Result : acc1 camp1

                                       acc2  camp2

                                       acc3  null

                                       acc4  camp2  

    But, When I use the same approach to bind with my whole query its give me following error.

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

    My Whole Query is :

     var CustomerList = (from c in context.ContactSet

                   join co in context.ConnectionSet on c.ContactId.Value equals co.Record1Id.Id

                   join ac in context.AccountSet on co.Record2Id.Id equals ac.AccountId.Value                    

                  join ca in context.CampaignSet on ac.AccountId.Value equals ca.exch_CampaignAccount.Id into gr

                   from cjoined in gr.DefaultIfEmpty()

                   select new CustomerList

                   {

                       FullName = c.FullName,

                       CampaignName = cjoined.Name

                   }).ToList();

    Please suggest any supported approach to get desired result.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans