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)

Dynamics CRM developer Question :- Linq Query to do 2 left outer join on Opportunity, Account, Contact

(0) ShareShare
ReportReport
Posted on by 205

I am trying to use Linq query to get the Opportunity data and its Parentaccountid Account Fields and its ParentCotnactId contact Full Name in one Linq query.

Most of the time Opportunity may have account associated with that but it may not have parentcontactid associated with that. So i need to do left outer join but for some reason it didn't work.

can any one assist on this??

  Dim oppties = From opt In context.OpportunitySet
                            From act In context.AccountSet.Where(Function(A) A.AccountId = opt.ParentAccountId.Id).DefaultIfEmpty()
                            From cnt In context.ContactSet.Where(Function(C) C.ContactId = opt.ParentContactId.Id).DefaultIfEmpty()
             Where opt.ParentAccountId.Equals(accId)
            Select New OpportunityInfo With {.OpportunityId = opt.OpportunityId.Value.ToString("B"),
                                             .ParentAccountId = opt.ParentAccountId.Id,
                                             .ParentAccountName = act.Name,
                                             .ParentAccountNumber = act.AccountNumber,
                                             .ProductGroup = opt.productgroup.Value,
                                             .MktSegment = act.DIVTeam,
                                             .EstRevenue = opt.ssco_EstimatedRevenue,
                                             .Topic = opt.Name,
                                             .CreatedOn = opt.CreatedOn,
                                             .Contact = If(cnt Is Nothing, String.Empty, cnt.FullName)}


 Dim oppties = (From opt In context.OpportunitySet Group Join
                               act In context.AccountSet On opt.ParentAccountId.Id Equals act.AccountId Into gr = Group From act In gr.DefaultIfEmpty() Group Join
                               cnt In context.ContactSet On opt.ParentContactId.Id Equals cnt.ContactId Into ct = Group From cnt In ct.DefaultIfEmpty()
            Where opt.ParentAccountId.Equals(accId)
                           Select New OpportunityInfo With {.OpportunityId = If(opt.OpportunityId.Value.ToString("B") Is Nothing, String.Empty, opt.OpportunityId.Value.ToString("B")),
                                                            .Topic = If(opt.Name Is Nothing, String.Empty, opt.Name),
                                                            .MktSegment = If(act.DIVTeam Is Nothing, String.Empty, act.DIVTeam),
                                                            .EstRevenue = If(opt.ssco_EstimatedRevenue Is Nothing, 0.0, Math.Round(Decimal.Parse(opt.EstimatedRevenue), 2)),
                                                            .CreatedOn = If(opt.CreatedOn Is Nothing, Nothing, opt.CreatedOn),
                                                            .ProductGroup = If(opt.productgroup Is Nothing, String.Empty, opt.productgroup.Value),
                                                            .Contact = If(cnt.FullName Is Nothing, String.Empty, cnt.FullName),
                                                            .ParentAccountId = If(opt.ParentAccountId Is Nothing, Nothing, opt.ParentAccountId.Id),
                                                            .ParentAccountName = If(act.Name Is Nothing, String.Empty, act.Name),
                                                            .ParentAccountNumber = If(act.AccountNumber Is Nothing, String.Empty, act.AccountNumber)
                                                           })


*This post is locked for comments

I have the same question (0)
  • Nicksoft Profile Picture
    205 on at
  • Nicksoft Profile Picture
    205 on at

    Any Assistance on this??

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