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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum
Under review by Community Managers

Under review

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

What is the MAX. level of relations I can get using QueryExpression? (Dynamics SDK, C#)

Posted on by 165

Hello

This code retrieves info about Contact (Parent entity) and Contact->Account (relations)

How Can I get related obhect of that Account?

I mean:

Contact->Account-->Account ?

Contact->Account-->Account -> Opportunity ?

Is this possible?

public void GetContact_Account_Relation()
{
//Create the request
RetrieveRequest request = new RetrieveRequest();
request.ColumnSet = new ColumnSet(true);
request.Target = new EntityReference("contact", Guid.Parse("fea2da35-6c8b-e911-a81a-000d3aba0968")); //parent

//связываем контакт и аакаунт
var relations = new RelationshipQueryCollection();

//relation from contact to aacount
var relationship = new Relationship
{
SchemaName = "contact_customer_accounts" //!!! not parentcustomerid (relation)
};

var query = new QueryExpression
{
EntityName = "account",
ColumnSet = new ColumnSet(true)
};

//contact (0) -> account (1)
var rel1 = new System.Collections.Generic.KeyValuePair<Relationship, QueryBase>(relationship, query);

relations.Add(rel1);

request.RelatedEntitiesQuery = relations;

Entity entity = (Entity)((RetrieveResponse)service.Execute(request)).Entity;
}

Thank you

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans