Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the entities “collection” and “store” associated with a N:N relationship “collection_store”. I want to use a fetchXML to retrieve the collections associated to a store, by avoiding duplicates (I’m expecting to retrieve only two records even if one collection is associated to two different stores): to achieve it, inside the fetch expression I changed the value of the property “distinct” to “true” but it did not work.

What I have tried:

static List<Entity> GetCollectionsInStore(CrmServiceClient serviceClient)
{
     FetchExpression query = new FetchExpression(@"<fetch version=""1.0"" output-format= ""xml-platform"" mapping =""logical"" distinct=""true"">
	<entity name=""collection"">
           <attribute name=""collectionid"" />
           <link-entity name=""collection_store"" from=""collectionid"" to=""collectionid"" intersect=""true"">
             <all-attributes />
           </link-entity>
        </entity>
</fetch> ");

var collectionsInStore = new List<Entity>();
collectionsInStore = serviceClient.RetrieveMultiple(query).Entities.ToList();
return collectionsInStore ;
}
Posted
Updated 20-Dec-20 9:58am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900