Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Avoid duplicates in fetch expressions

(0) ShareShare
ReportReport
Posted on by 355

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.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Avoid duplicates in fetch expressions

    Hello,

    Remove from your link-entity part <all-attributes /> and that should fix your issue.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans