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 :
Microsoft Dynamics CRM (Archived)

Linkentity within queryexpression

(0) ShareShare
ReportReport
Posted on by

Hey guys.. 
I found sample code about link entity:

QueryExpression SrchQry = new QueryExpression();

           SrchQry.EntityName = A.LogicalName;

           SrchQry.ColumnSet = new ColumnSet("a", "b", "c");

           SrchQry.Criteria.AddCondition("country", ConditionOperator.Equal, new string[] { strcodigo });

LinkEntity EntityB = new LinkEntity(A.LogicalName, B.LogicalName, "aid", "aid", JoinOperator.Inner);

           EntityB.Columns = new ColumnSet("a", "b");

           EntityB.EntityAlias = "Entb";

LinkEntity EntityC = new LinkEntity(B.LogicalName, C.LogicalName, "bid", "bid", JoinOperator.Inner);


as you can se, there is "aid" and "bid".  I still did'nt get on with that "aid" and "bid". Can you tell me what the mean of "aid" and "bid" there.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    It has following syntax

    LinkEntity EntityB = new LinkEntity(related entity, primary entity, lookup in related entity, primary attribute of primary entity, join);

    Thanks

  • Suggested answer
    ShahXu Profile Picture
    1,515 on at

    linkEntity.png

    hope it will gives you complete idea.

  • Community Member Profile Picture
    on at

    Does contactid is the primary key from child entity (contact) and customerid is the foreignkey in parent entity (contract) ?

    So if in SQL, it would be something like this:

    SELECT Contact.a, Contract.b

    FROM Contact

    INNER JOIN Contract

    ON Contact.Contactid = Contract.CustomerID;

  • Community Member Profile Picture
    on at

    hii,

    is "aid" is primary key in child entity and foreign key in parent entity ?

  • Suggested answer
    ShahXu Profile Picture
    1,515 on at

    yep in my case i wanted to compare contactid with the customerid.

    you are pretty much correct.

  • Verified answer
    ShahXu Profile Picture
    1,515 on at

    you can compare any two values one from linkFromEntity and LinkToEntity.

    it is not necessary that you have to give P.K and F.K

    Just like if you want to compare firstname column on both contract and contact then you write firstname column name

  • Verified answer
    BackToTheCrm Profile Picture
    on at

    Hello Saraswati,

    Yes, contactid is the primary key from contact and customerid is the foreignkey in contract

  • Community Member Profile Picture
    on at

    ohh i see..

    thanks Shahzeb..

    now i have another case. Based on sql query i made,  i want to retrieve value from Contract. Where the contract entity is child entity. But the type of field that i want to retrieve is lookup field.

    for condition clause, i can use this :

    .AddCondition("new_gender", ConditionOperator.Equal, 100000000);

    so, how about retrieve value from lookup field in child entity ?

  • Community Member Profile Picture
    on at

    ohh i see..

    thanks Shahzeb..

    now i have another case. Based on sql query i made,  i want to retrieve value from Contract. Where the contract entity is child entity. But the type of field that i want to retrieve is lookup field.

    for condition clause, i can use this :

    addCondition("new_gender", ConditionOperator.Equal, 100000000);

    so, how about retrieve value from lookup field in child entity ?

  • Suggested answer
    ShahXu Profile Picture
    1,515 on at

    the condtion you are showing here as sample is of optionset not lookup..

    lookup condition can be added like this simply

    ContractQuery.Criteria.AddCondition("customerid", ConditionOperator.Equal, ContactId);

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans