asp.net - Sorting a nested list array in C# -


i trying sort nested array of elements in asp.net , having bit of trouble. have playlist has model so:

public class playlist {     public playlist()     {         this.date = new list<dates>();     }     [key]     public int id { get; set; }     public string userid { get; set; }     public list<dates> date { get; set; }      public class dates     {         [key]         public int dates_id { get; set; }         public list<places> place {get; set;}     }      public class places     {         [key]         public int places_id { get; set; }         public string id { get; set; }     } }` 

as can see nested array of objects, dates, array of objects, places.

what doing pulling out data so:

playlist = db.playlists.where(e => e.userid.equals(userid)).orderby(q => q.id).include("date.place").tolist();

what realized places in date object wasn't being pulled out in sorted array based on place_id, rather randomly. there way pull out playlist places ordered? .orderby(q => q.id) pull ordered list playlist , not nested objects.

you can arrange order of items in nested lists on client:

// fetch playlists given user id var playlist = db.playlists       .where(e => e.userid.equals(userid))       .orderby(q => q.id)       .include("date.place")       .tolist();  // order places , dates id's foreach(var item in playlist) {    foreach(var d in item.dates)    {         d.places.sort((left, right) =>           left.id.compareto(right.id));    }     item.dates.sort((left, right)=>       left.id.compareto(right.id)); } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -