CRM 4.0 XRM Advanced Extensions SetLink and AddLink do not seem to work

Pertanyaan CRM 4.0 XRM Advanced Extensions SetLink and AddLink do not seem to work

  • 18 Mei 2012 15:01
     
      Memiliki Kode

    Referring to this article in msdn

    http://msdn.microsoft.com/en-us/library/ff681570.aspx

    I would be interested to find out if anyone has had any success with SetLink 

    I am trying to set a link between two entities using very similar syntax to below, I get no error just the link record doesn't show up in the MS_CRM database. 

    var contact = crm.GetEntities("contact").Where(c => c.GetPropertyValue<string>("fullname") == "Allison Brown").Single();
    
    var account = crm.GetEntities("account").Where(c => c.GetPropertyValue<string>("name") == "Contoso").Single();
    
    contact.GetPropertyValue<string>("fullname"), account.GetPropertyValue<string>("name")); 
    
    // Specify the name of the relationship.
    crm.SetLink(contact, "contact_customer_accounts", account);
    crm.SaveChanges();

    I am about to give up and use a AssociateEntitiesRequest object with the CrmService request (as below) but before I give up on Xrm  I thought I would ask if anyone else had come across problems with SetLink and if so did you manage to resolve the problem?

    CrmService service =MyProg.GetCrmService(crmServerUrl, orgName);
    service.PreAuthenticate = true;

                    Moniker moniker1 = new Moniker();
                    moniker1.Name = "ent_1";
                    moniker1.Id = new Guid("D4278D4D-ECD5-494B-ACAF-BA6A9688A12A");

                    Moniker moniker2 = new Moniker();
                    moniker2.Name = "ent_2;
                    moniker2.Id = new Guid("29F39492-7D4F-DE11-9C44-005056921C55");

                    AssociateEntitiesRequest request = new AssociateEntitiesRequest();

                    request.Moniker1 = moniker1;

                    request.Moniker2 = moniker2;

                    request.RelationshipName = "rel_tablename";

                    service.Execute(request);

    Thank you for your time

Semua Balasan

  • 25 Juni 2012 20:27
     
     
    I ran into this issue as well. But kinda coming from ef4, i tried to do attach first on the source and target entity, so the ctx knows what are involved, then call the addlink/savechanges(). Then it should work.