many to Many Entity Relations Insert Data RRS feed

  • General discussion



    I have defined a many-to-many relationship between Contact entity and custom entity Concepts ,i want to add new contact and concepts related to contact  using crmservice C#.how can i do this?

    Tuesday, August 31, 2010 6:40 PM

All replies

  • I am trying the code sample that you have given..

    facing one issue.

    when i write this code given below it says "Type or Namespace could not be found" 

    AssociateEntitiesRequest request = new AssociateEntitiesRequest();

    how to get resolve this?

    Tuesday, August 31, 2010 7:10 PM
  • I am able to access all other entities except these from my CRMService.



    one of the blog says the entities should have to permissions to Create/Read/Update.

    what could be the reason?

    is there any other way to resolve this?

    Tuesday, August 31, 2010 8:07 PM
  • Hello Rhett,

             Now i am able to associate records with  the entities.Could you help me how to remove records or update records with some other set of values with other entities.

    Monday, September 6, 2010 7:44 PM
  • Could you explain a little more about what you want to do with Remove, Update, etc..
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Monday, September 6, 2010 8:43 PM
  • Basically i want to Associate the set of departments  records to a customer in Many to Many Relation. In future customer might want to get Associated to some other set of Departments.

    Code for Associating the Customer-Department Many to Many Relation.

     Moniker moniker1 = new Moniker();
          Moniker moniker2 = new Moniker();
          string _ConceptGuid=string.Empty;
          //for(int i=0; i<response.DCDepartments.Count();i++)
          if (response.DCDepartments.Count() > 0)
            new_udiconcept udico = new new_udiconcept();
            foreach (DCCustomDepartment depobj in response.DCDepartments)
              var conceptGuidId= from c in allConceptsquery
                       where c.DepartmentNames == depobj.Name
                        select c.DepartmentId.ToString();
              foreach (var _concept in conceptGuidId)
                _ConceptGuid = _concept.ToString();
                AssociateEntitiesRequest _request = new AssociateEntitiesRequest();
                AssociateEntitiesResponse _response = new AssociateEntitiesResponse();
                moniker2.Id = new Guid(_ConceptGuid);
                moniker2.Name = EntityName.new_dept.ToString();
                _request.Moniker1 = moniker1;
                _request.Moniker2 = moniker2;
                _request.RelationshipName = "new_new_dept_contact";            
              catch(Exception ex)
                throw ex;

    In the above code response.DCDepartments gets the list of departments that has to be associated to customer ie contact entity in CRM with custom entity new_dept. later on  customer might like to change to different set of departments(ie  update operation). 


    Monday, September 6, 2010 9:29 PM
  • -The many to many relations have two types of action, Associate and Disassociate. You have already done the Associate so here is the Disassociate Entities Request http://msdn.microsoft.com/en-us/library/cc152496.aspx
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Monday, September 6, 2010 9:48 PM
  • Tuesday, September 7, 2010 11:30 AM
  • I've written some new utility code for expressly this purpose:  http://crmentropy.blogspot.com/2010/09/nn-relationship-utility-code-javascript.html
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Wednesday, September 8, 2010 10:31 PM