We have a requirement where we need to sort the entity collection in descending order by date in plugin . Can someone help me how to do that?
why don't configure the view where the data will be shown to be sorted by the date? you don't need to implement this logic inside a retrievemultiple plugin
We want to set the entity collection (this data is coming from fetch xml aggregate query) data to the virtual entity . So for this we need to have entity collection before running this following code , we need to sort this Entity collection order by date descending.
context.OutputParameters["BusinessEntityCollection"] = entityCollection;
And with the help of view it is not possible.
the entityCollection in your line of code is probably defined as
EntityCollection entityCollection = new EntityCollection();
if you define your records like
List entities = new List();
you can do this line to add the entities like
entityCollection.Entities.AddRange(entities);
so you just need to sort (with LINQ) the List<Entity> with your criteria.
Hi,
Try below code
var responseRoomAllocDetails=roomAllocDetails.Entities.OrderByDescending(x => x.Attributes["createdon"]).Select(x => x);
var responseRoomAllocDetails = entityCollection.Entities.OrderByDescending(x => x.Attributes["pp_lastlogindatetime"]).Select(x => x);
This code is not showing any error , but what i am trying to achieve is still not achievable for me
It is not working because you are passing original EntityConnlection object to output parameter
You need to do as below
var entityCollection = new EntityCollection<TEntity>();
foreach (var item m in list)
{
entityCollection.Add(m);
}
Replace list with responseRoomAllocDetails
Then pass entityCollection to output parameter
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Rishabh Kanaskar 258
MVP-Daniyal Khaleel 186
Tom_Gioielli 130 Super User 2025 Season 2