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

How get related objects with QueryExpression?

(0) ShareShare
ReportReport
Posted on by 165


Hello

I have 2 entities: Contact and Account.

Account linked to Contact by field "parentcustomerid"

I wrote query:

(sorry I can't mark it as code,  because there is a error in this forum:( )

public bool MakeDynamics365Call()
{
var query = new QueryExpression
{
EntityName = "contact",
ColumnSet = new ColumnSet(true),
Criteria = new FilterExpression
{
Conditions = {
new ConditionExpression {
AttributeName = "emailaddress1",
Operator = ConditionOperator.Equal,
Values = { "b5055354@urhen.com" }
}
}
}
};

var relationship = new Relationship();
relationship.SchemaName = "parentcustomerid";
var relatedEntity = new RelationshipQueryCollection();
relatedEntity.Add(relationship, query);

RetrieveRequest request = new RetrieveRequest();
request.RelatedEntitiesQuery = relatedEntity;
request.ColumnSet = new ColumnSet("accountid");

//real account ID
request.Target = new EntityReference { Id = Guid.Parse("cf731978-20cb-e911-a828-000d3aba5e95"), LogicalName = "account" };

var res = service.RetrieveMultiple(query);
return true;
}

As result I have:
pastedimage1567259206576v1.png

No Related Entities!!!

What I did wrong?

I expected 1 related Entity - Account!

Thank you

I have the same question (0)

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

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