How to get Lookup of a parent using Linq Query..?
How to get Lookup of a parent using Linq Query..?
Hi mrutyunjai,
Was code run successfully?
Regards,
Clofly
Hi mrutyunjai,
Feel free to ask any question if you had encountered any problem when running the code.
Regards,
Clofly
Thank you Clofly, i will try this
Hi mrutyunjai,
We can combine two "join on" to get parent record of parent record.
For example, Lead > Contact(Existing Contact?) > Account(Company Name).
Clofly Mao > Clofly Mao > Contoso, Ltd.
public static void queryEntity(IOrganizationService organizationService) { OrganizationServiceContext orgContext = new OrganizationServiceContext(organizationService); var myLinqQuery = from leadEntity in orgContext.CreateQuery("lead") join contactEntity in orgContext.CreateQuery("contact") on leadEntity["parentcontactid"] equals contactEntity["contactid"] join accountEntity in orgContext.CreateQuery("account") on contactEntity["parentcustomerid"] equals accountEntity["accountid"] select new { fullname = leadEntity.GetAttributeValue("fullname"), contactname = contactEntity.GetAttributeValue("fullname"), accountname = accountEntity.GetAttributeValue("name"), accountphone = accountEntity.GetAttributeValue("telephone1"), }; StringBuilder builder = new StringBuilder(); foreach (var results in myLinqQuery) { builder.Append("============================================" "\n"); builder.Append(" lead fullname: " results.fullname ", parent contact: " results.contactname ", parent account name of parent contact: " results.accountname ", parent account phone of parent contact: " results.accountphone "\n"); builder.Append("============================================"); } Console.WriteLine(builder.ToString()); }
Regards,
Clofly
André Arnaud de Cal...
292,516
Super User 2025 Season 1
Martin Dráb
231,409
Most Valuable Professional
nmaenpaa
101,156