I have two custom entities with N:N relationship. 1) Membership , 2) Offer
I have used subgrid on form of Membership and Offer to shows related records.
I am writing one plugin function where I have one membership entity record id as input and I want to get all related records of Offer entity as output. I have tried following code but I couldn't get related offer entity records.
entity1 = "new_membership" , entity2 = "new_offer" , relationshipEntityName = "new_new_membership_new_offer"
public List<new_offer> getAllOffersFromMembership(string entity1,string entity2, string relationshipEntityName, string Id)
{
QueryExpression query = new QueryExpression(entity1);
query.ColumnSet = new ColumnSet(true);
LinkEntity linkEntity1 = new LinkEntity(entity1, relationshipEntityName, "new_membershipid","new_membershipid", JoinOperator.Inner);
LinkEntity linkEntity2 = new LinkEntity(relationshipEntityName, entity2, "new_offerid","new_offerid", JoinOperator.Inner);
linkEntity1.LinkEntities.Add(linkEntity2);
query.LinkEntities.Add(linkEntity1);
linkEntity2.LinkCriteria = new FilterExpression();
linkEntity2.LinkCriteria.AddCondition(new ConditionExpression( “new_membershipid”, ConditionOperator.Equal, Id));
EntityCollection collRecords = service.RetrieveMultiple(query);
//To Do : Get offer entity records
}
As I am new in MS CRM, may be I am doing some silly mistakes.
Thanks in advance.