简体   繁体   中英

Dynamic CRM 2011 - How to add one entity as a relationship of another entity?

I am new to CRM, so please excuse my excuse me if I potential misuse a term.

I have two custom entities (EntityA and EntityB) and EntityA has a 1:N relationship to EntityB. I have two instances of EntityA(EntityA1 and EntityA2) and one instance of EntityB(EntityB1); EntityB1 is a child of EntityA1. I want to make EntityB1 a child of EntityA2, too.

I currently have a plug-in that retrieves these entities. How do I relate them to one another?

I read this( Dynamics CRM 2011 - How to relate two different entities ) and I wanted to post a comment, but was unable to due to not have 50 reputation. I wanted to ask what would happen if I did

new_voucher.new_paymentid = new EntityReference(EntityA1); //new_voucher is EntityB1 new_voucher.new_paymentid = new EntityReference(EntityA2);

would that add the voucher as a child to both EntityA1 and EntityA2 or would that severe the connection to EntityA1? This would allow EntityB1 to find its parents, but would EntityA1 and EntityA2 be able to find its child?

What you are describing is a N:N (many-to-many) relationship while what you have defined is a 1:N (one-to-many) relationship.

A 1:N relationship puts a lookup on N (child) side to create the link to the 1 (parent) side. Therefore a child (EntityB) can be related to only one parent (EntityA). This is why EntityB1 cannot be a child of both EntityA1 and EntityA2.

AN:N relationship will use an intersect table so that any instance of EntityA can be related to any instance of EntityB. This will allow you to accomplish what you want in CRM 2011.

You configure N:N relationships using the CRM GUI as detailed at: http://www.dynamicscrmtrickbag.com/2011/05/08/many-to-many-relationships-in-dynamics-crm-2011/ .

Your plugin code will need to use the Associate/Disassociate messages to create the relationships as shown here: http://charithrajapaksha.blogspot.com/2011/08/creating-many-to-many-records-in-crm.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM