title: Retrieve N:N Relationship in Dynamics Crm
body: <p>Currency entity is associated N:N Relationship with Lead.Now I'm trying to Retrieve associated Currency with the lead.i'm getting problem transaction currency does'nt contain attribute with leadid.could any references plz...</p>
  
  <pre class="lang-c# prettyprint-override"><code>if (context.InputParameters.Contains("Target") &amp;&amp; (context.InputParameters["Target"]) is Entity)
  {
      Entity en = (Entity)context.InputParameters["Target"];
      QueryExpression _Query = new QueryExpression
      {
          EntityName = "transactioncurrency",
          ColumnSet = new ColumnSet(true),
          LinkEntities = 
          { 
              new LinkEntity 
              { 
                  Columns=new ColumnSet(true),
                  LinkFromEntityName="lead",
                  LinkFromAttributeName="leadid",
                  LinkToEntityName="new_lead_transactioncurrency",
                  LinkToAttributeName="transactioncurrencyid",
                  LinkCriteria=new FilterExpression  
                  {
                      FilterOperator=LogicalOperator.And,
                      Conditions=
                      { 
                          new ConditionExpression  
                          {
                              AttributeName="transactioncurrencyid",
                              Operator=ConditionOperator.Equal,
                              Values={ en.Id }
                          }
                      }
                  }
              }
          }
      };
  
      EntityCollection entitycollect = service.RetrieveMultiple(_Query);
      int entitycount = entitycollect.Entities.Count;
  }
  </code></pre>