locked
Problem with N:N Relationships RRS feed

  • Question

  • Hi Guys,

    I have a problem with N:N entity relationship.

    We are using Live CRM  and we have two N:N entities that are linked to Contact entity. One is new_contact_supplier and other one is new_contact_employee.

    From CRM I am able to associate these record associations. I am trying the same using code using AssociateEntitiesRequest. It is working fine for 'new_contact_supplier' and the same code is giving Error for 'new_contact_employee'. Here is the error I am getting when associating contact record with Employee.

    "Entity Relationship new_contact_employee was not found in the metadata" . what is the problem with this relationship?

    I am unable to pointout the issue. Please help me.

    Thanks and Regards

    Janu

    Monday, July 26, 2010 4:22 PM

Answers

  • AssociateEntitiesRequest request = new AssociateEntitiesRequest();
    
    request.RelationshipName = "new_contact_new_employee";
    
    request.Moniker1 = new Moniker();
    request.Moniker1.Name = EntityName.contact.ToString();
    request.Moniker1.Id = <contact id>;
    
    request.Moniker2 = new Moniker();
    request.Moniker2.Name = "new_employee";
    request.Moniker2.Id = <employee id>;
    
    "new_contact_new_employee" is actually the schema-name expected by the function; the relationship hides a special entity called "new_contact_employee" which can be exposed or accessed through Retrieve, RetrieveMultiple, and filtered views for SQL queries.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    • Proposed as answer by Mayank Pujara Wednesday, July 28, 2010 9:41 PM
    • Marked as answer by Jim Glass Jr Tuesday, August 3, 2010 6:53 PM
    Wednesday, July 28, 2010 8:00 PM
    Moderator
  • Dave,

    I know this is a fairly old thread but I ran into the same error although I'm using the xRM/ADX generated classes instead of the web service.  It drove me nuts - but I found that the problem, at least in my case, is that if you do not have the same value for the relationship "Name" and "Relationship Entity Name" in the Relationship Definition section, it will fail with the error message Janu mentioned.  Your post helped in that it gave me some sanity that I was putting the right value in there.  Then it occurred to me - I had changed the Name to something other than the default.  So, I tried setting the Name and Relationship Entity Name with the same values and it worked fine.

    I've tried it at least three times with various names, but for example, if I specify the the "Name" as "new_jeff" and the "Relationship Entity Name as "new_ballard" and regenerate my xRM classes, it fails.  If I name them both "new_jeff", it works just fine.  Obviously those are poor naming choices, but they worked well for my test.  :)

    I would guess this would be a bug, but I'm not sure.  Hopefully this helps someone else.

    Jeff


    Tuesday, November 23, 2010 10:48 PM

All replies

  • Hi, Janu.

    Could you publish full code here?


    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    Monday, July 26, 2010 4:45 PM
    Moderator
  • Is it possible that you used the schema-name of the entity, rather than the schema-name of the relationship in your AssociateEntitiesRequest?  That's what the error seems to suggest.  I'm doubtful they could actually have the same name, so why don't you open the relationship in the Customization UI, and examine the name of it, and make sure that is what's being passed to the "RelationshipName" member of the AssociateEntitiesRequest object.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, July 26, 2010 4:51 PM
    Moderator
  • you need to put Name from the relationship defination and i think you are putting relationship entity name here..

    to check relationship defination  name and relationship defination entityname open relevant entity and go to N:N relationship and then open this relationship and it will have both these names...

     

    Also make sure both entities are published in CRM..for more informatin check out following article..

    http://blogs.msdn.com/b/crm/archive/2008/02/14/crm-4-0-relationships-explained.aspx


    MayankP My Blog My twitter
    Tuesday, July 27, 2010 9:20 PM
  • Thank you very much guys for you replies.

    I am 100% sure, I am using the entity name of the relationship name. Here I did one thing while creating this customization. I changed the name of the n to n relation entityname.

    Because of that my relationshipname and entityname are like this.

    RelationshipName: new_contact_new_employee

    Relationship EntityName: new_contact_employee

     

    But I am able to retrieve the records programmatically by using the entity name of the relationship i.e 'new_contact_employee' (employees attached to a particular contact).

    But I am still not able to associate the records programmatically.

    Is that name change causing the problem?

    Please help me. Thanks in Advance.

    Thanks and Regards
    Janu

    Wednesday, July 28, 2010 7:24 PM
  • AssociateEntitiesRequest request = new AssociateEntitiesRequest();
    
    request.RelationshipName = "new_contact_new_employee";
    
    request.Moniker1 = new Moniker();
    request.Moniker1.Name = EntityName.contact.ToString();
    request.Moniker1.Id = <contact id>;
    
    request.Moniker2 = new Moniker();
    request.Moniker2.Name = "new_employee";
    request.Moniker2.Id = <employee id>;
    
    "new_contact_new_employee" is actually the schema-name expected by the function; the relationship hides a special entity called "new_contact_employee" which can be exposed or accessed through Retrieve, RetrieveMultiple, and filtered views for SQL queries.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    • Proposed as answer by Mayank Pujara Wednesday, July 28, 2010 9:41 PM
    • Marked as answer by Jim Glass Jr Tuesday, August 3, 2010 6:53 PM
    Wednesday, July 28, 2010 8:00 PM
    Moderator
  • As I said previously you need to use relationshipname and it will work fine..

    RelationshipName: new_contact_new_employee [correct name to be used]

    Relationship EntityName: new_contact_employee

     Anyways, David has provided correct code for this in above thread...

     


    MayankP My Blog My twitter
    Wednesday, July 28, 2010 9:44 PM
  • Thank you very much David and MayaKP for your replies.

    With relationship name also it is not working.  I tried with both Relationshipname as well as the relationship entityname but no luck.

    Unable to findout the problem. Looking forward to you guys.

     

    Thanks and Regards

    Janu

    Tuesday, August 3, 2010 6:04 PM
  • If you're still experiencing the problem, I encourage you to dump your code into this thread for analysis.  MayankP and I have given you the fullest, most complete explanation of the AssociateEntities message and its use for your scenario.  Please also include error messages exposed by enabling tracing in CRM .
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Tuesday, August 3, 2010 8:10 PM
    Moderator
  • Hello David,

     

     I am having the similar kind of issue.i want to relate records using c# code.

    here below is the code have written.

    Moniker moniker1=new Moniker();
    moniker1.Id=cmcontactid;
    moniker1.Name=EntityName.contact.ToString();
    
    
    Moniker moniker2=new Moniker();
    moniker2.Id=new Guid(depobj.Name.ToString());          moniker2.Name=EntityName.new_udiconcept.ToString();
    
    AssociateEntitiesRequest request = new AssociateEntitiesRequest();
    

     In my case i am not able to see the CRMService Classes in my code. how do i resolve this?

     AssociateEntitiesRequest

    AssociateEntitiesResponse

    Tuesday, August 31, 2010 8:43 PM
  • Hi Abdul Raziq,

    YOu need to add the Microsoft.Crm.sdk.dll and Microsoft.crm.sdktypeproxy.dll to your project.

    Or

    you can use the webservices to access the CRM classes.

     

    Thanks and Regards
    Janu

    Wednesday, September 1, 2010 4:57 AM
  • i am using  webservices to access the CRM classes. but i am not getting access to these classes "AssociateEntitiesRequest , AssociateEntitiesResponse".

     

    Thanks and Regards

    Raziq

    Wednesday, September 1, 2010 5:19 PM
  • Dave,

    I know this is a fairly old thread but I ran into the same error although I'm using the xRM/ADX generated classes instead of the web service.  It drove me nuts - but I found that the problem, at least in my case, is that if you do not have the same value for the relationship "Name" and "Relationship Entity Name" in the Relationship Definition section, it will fail with the error message Janu mentioned.  Your post helped in that it gave me some sanity that I was putting the right value in there.  Then it occurred to me - I had changed the Name to something other than the default.  So, I tried setting the Name and Relationship Entity Name with the same values and it worked fine.

    I've tried it at least three times with various names, but for example, if I specify the the "Name" as "new_jeff" and the "Relationship Entity Name as "new_ballard" and regenerate my xRM classes, it fails.  If I name them both "new_jeff", it works just fine.  Obviously those are poor naming choices, but they worked well for my test.  :)

    I would guess this would be a bug, but I'm not sure.  Hopefully this helps someone else.

    Jeff


    Tuesday, November 23, 2010 10:48 PM
  • Good information!  Thanks for adding to the thread, Jeff.  I don't use the xRM class generation code, but I believe it would be a bug that it doesn't accommodate the possible variances between the schema names of the relationship and the relationship-entity.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Tuesday, November 23, 2010 11:00 PM
    Moderator
  • Dave,

    Better late than never, I finally had a chance to research this a little more.  I was never actually able to reproduce the issue using the web service methods as Janu, but could reproduce it by using the advanced developer extensions code.  It was different than what I expected - I expected both to fail and only the advanced developer extensions did.  Oh, well.  Here's the post with my results.

    http://www.toplinestrategies.com/dotneters/technology/error-with-advanced-developer-extensions/

    I will say I love the fact that the developer extensions significantly cuts the number of lines of code!

    Jeff

    • Edited by Jeff Ballard Friday, January 28, 2011 4:35 PM Updated post with correct URL to blog entry
    Friday, January 28, 2011 4:31 PM