locked
how to get related entities in CRM 2011? RRS feed

  • Question

  • Hello Everyone

    I have following situation.

    Account entity is linked to a custom office entity (1:N).

    In C# code, I retrieve all accounts using <serviceContext>.AccountSet. I get all the accounts.

    But, when I try to get the relatedentities it returns 0. Even when I try to get the values directly from the relationship object (new_account_new_office), it returns null.

    Any suggestions or ideas?

    Thanks

     


    • Edited by WPF_Dev Friday, May 25, 2012 7:20 PM
    Friday, May 25, 2012 6:51 PM

Answers

  • Hi,

      you might need to call

      account.GetRelatedEntities(context, "contact_customer_accounts");

      for every account.

      (where "contact_customer_accounts" is the name of the relationship. Should be different in your case)

     


    Alex Shlega, GotchaHunter.Net

    • Marked as answer by WPF_Dev Monday, May 28, 2012 6:40 PM
    Monday, May 28, 2012 4:48 PM

All replies

  • HI WPF_Dev,

                    I guess you are using ODAT services, on that case I would suggest installing the CRM 2011 OData Query Designer from codeplex ( http://crm2011odatatool.codeplex.com/) that will help you creating the ODATA query to include the related entities.


    Regards,
    Damian Sinay

    Saturday, May 26, 2012 8:10 AM
  • Hi dsinay

    Thanks for the reply.

    I am not using OData. I am using LINQ.

    Any idea why the the relationship is returning null?

    Thanks

    Monday, May 28, 2012 3:59 PM
  • Hi,

      you might need to call

      account.GetRelatedEntities(context, "contact_customer_accounts");

      for every account.

      (where "contact_customer_accounts" is the name of the relationship. Should be different in your case)

     


    Alex Shlega, GotchaHunter.Net

    • Marked as answer by WPF_Dev Monday, May 28, 2012 6:40 PM
    Monday, May 28, 2012 4:48 PM