I created a fetch expression to retrieve all the collections which are related to a store.
As a collection can be related to more than one store, I have an N:N relationship between the two entities.
I'm using the following fetch expression to retrieve the collections and set the property distinct to true to avoid duplicates, see line 3:
static void CollectionsInStore(CrmServiceClient serviceClient) { FetchExpression query = new FetchExpression(@" (); collectionsInStores = serviceClient.RetrieveMultiple(query).Entities.ToList(); var index = 1; Console.WriteLine(" \n<<< Collections related to a store >>> \n"); foreach (Entity c in collectionsInStores) { Console.WriteLine($" ***Collection {index} ***\n"); Console.WriteLine(" Name: " c.Attributes["name"] "\n"); Console.WriteLine(" ___________________________________ \n"); index ; } }
But I still get duplicates: as the same Collection "Collection X" is present both in "Store One" and in "Store Two", I get the same record "Collection X" twice.