locked
How to use LINQ to get associated records? RRS feed

  • Question

  • Hi,

    I am writing my first plugin, based on an example I found.
    http://community.dynamics.com/product/crm/crmtechnical/b/mscrmshop/archive/2012/02/23/plugin-to-update-children-records-when-parent-record-is-upadated.aspx

    I have an Entity Employee and an Entity Employee_Confidential. There is a 1..n relationship between Employee and Employee_Confidential.

    If the full name of the employee changes I want to change the full name set on the associated Employee_Confidential (One or more).

    I am almost there. There is one thing that puzzels me: what field on the 'child' is used to record the ID of the associated 'parent'. The system knows somehow which records are associated because it can display them in an 'Associated view'.

    I want to use LINQ to lookup the records. But I need to know how to find out what I have to put on place of the ??? in the code below.

    var res = from c in ServiceContext.CreateQuery("pwg_employee_confidential")                            
    where c["???"].Equals(entity.Id)                            
    select c;   

    Can someone point me in the right direction?

    Thanks.

    - Ton -

    Thursday, June 14, 2012 9:55 AM

Answers

  • Found it myself.

    I had to look into the 1..n relationship. There the mapping of the parent ID to the child ID is setup and named.

    • Marked as answer by tvdpol Thursday, June 14, 2012 11:42 AM
    Thursday, June 14, 2012 11:42 AM