Показать сообщение отдельно
Старый 25.11.2009, 05:08   #1  
Blog bot is offline
Blog bot
Участник
 
25,646 / 848 (80) +++++++
Регистрация: 28.10.2006
crmdude: Self Referential Many to Many Relationship
Источник: http://crmdude.wordpress.com/2009/11...-relationship/
==============


I created a Many to Many relationship to and from the User entity- nothing out of the ordinary. I then tried to programmatically retrieve the records associated to this relationship (ie, to the intersect table). I specified the following intersect rule:


LinkEntity filteringLink = new LinkEntity();
filteringLink.LinkFromEntityName = relationshipName;
filteringLink.LinkFromAttributeName = secondaryEntityPK;
filteringLink.LinkToEntityName = secondaryEntityName;
filteringLink.LinkToAttributeName = secondaryEntityPK;
filteringLink.LinkCriteria = filter;

LinkEntity link = new LinkEntity();
link.LinkFromEntityName = primaryEntityName;
link.LinkFromAttributeName = primaryEntityPK;
link.LinkToEntityName = relationshipName;
link.LinkToAttributeName = primaryEntityPK;
link.LinkEntities = new LinkEntity[] { filteringLink };


But I kept getting an error saying: ” ‘geni_followedby’ entity doesn’t contain attribute with Name = ’systemuserid’.\n Platform\n”.

Looking at the database revealed the obvious issue- because it’s a self referential relationship, both key’s have the same name (systemuserid), so they get renamed to systemuseridone and systemuseridtwo. So I changed my code as follows (quick hack):


LinkEntity filteringLink = new LinkEntity();
filteringLink.LinkFromEntityName = relationshipName;
filteringLink.LinkFromAttributeName = secondaryEntityPK + "two";
filteringLink.LinkToEntityName = secondaryEntityName;
filteringLink.LinkToAttributeName = secondaryEntityPK;
filteringLink.LinkCriteria = filter;

LinkEntity link = new LinkEntity();
link.LinkFromEntityName = primaryEntityName;
link.LinkFromAttributeName = primaryEntityPK;
link.LinkToEntityName = relationshipName;
link.LinkToAttributeName = primaryEntityPK + "one"
link.LinkEntities = new LinkEntity[] { filteringLink };


Tagged: code, many to many


Источник: http://crmdude.wordpress.com/2009/11...-relationship/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.