locked
i'm not getting result using late bound query in dynamics crm plugin RRS feed

  • Question

  • i used the below code  to join account and contact.but i'm unable to get the result and not getting any error also.

    var getJoins = from c in OrgServiceCOntext.CreateQuery("contact").ToList()
                               join a in OrgServiceCOntext.CreateQuery("account").ToList()
                               on c.Attributes["contactid"] equals a["primarycontactid"]
                               select new
                               {
                                   contact_name = c["fullname"],
                                   account_name = a["name"]
                               };
    
                foreach (var item in getJoins)
                {
                    Console.WriteLine("=====================================================");
                    Console.WriteLine("getName" + item.account_name);
                    Console.WriteLine("getName" + item.contact_name);
                    Console.ReadLine();
                }
    could anybody help me on this?


    hsk srinivas


    • Edited by Ppandu Wednesday, September 17, 2014 6:31 AM
    Wednesday, September 17, 2014 6:28 AM

All replies

  • Check this link http://msdn.microsoft.com/en-in/library/hh210215.aspx
    Wednesday, September 17, 2014 6:47 AM
  • Using that link only wrote the code. but i'm unable to get result and error.

    hsk srinivas

    Wednesday, September 17, 2014 6:53 AM
  • Please post the error screen shots /details
    Wednesday, September 17, 2014 7:06 AM
  • Hello,

     There is slight modifications required to get your query working.

    1. ToList() has to load all the contacts and accounts into list before the join is made. so you probably will have to wait for a really long time before your results are loaded into memory (if at all). So please remove the toList from query.

    2. Based on the number of contacts and accounts available, the query again will take a very long time.

    3. if you are learning, please try to add a filter to your query to get quick result. try a query like this.

    var getJoins = from a in OrgServiceCOntext.CreateQuery("account")
                            join c in OrgServiceCOntext.CreateQuery("contact")
                            on a["accountid"] equals c["rio_groupid"]
                            where a.GetAttributeValue<string>("accountnumber") == "11280"
                            select new
                            {
                                contact_name = c["fullname"],
                                account_name = a["name"]
                            };

    Regards,

    Jithesh

    Wednesday, September 17, 2014 8:37 AM
  • but we have to evaluate 
    OrgServiceCOntext.CreateQuery("account")

    hsk srinivas

    Wednesday, September 17, 2014 8:45 AM
  • hello Srini ,

    the join will be evaluated. I have changed the order of account and contact since we have less accounts than contact. We also use a custom relationship between account and contact.

    sorry to confuse you. Basic idea is same. Remove toList and also add a filter to see if your query/connection got any issues. Once you get your first output, you can tweak your query further.

    let me know if you have any questions.

    regards

    Jithesh

    Wednesday, September 17, 2014 9:20 AM