2015-12-16 59 views
0

排序嵌套屬性如何將一個在地方排序嵌套列表:3所列出

JobCollection

名單

喬布斯(由字符串贊助商排序)項目

列表(排序INT訂單列表)

數據模型的類結構:

public class JobCollection 
{ 
     public string Collection { get; set; } 

     public virtual TrulyObservableCollection<Job> Jobs { get; private set; } = new TrulyObservableCollection<Job>(); 
} 

public class Job 
{ 
     public virtual JobCollection JobCollection { get; set; } 

     public string JobGUID { get; set; } = Guid.NewGuid().ToString(); 

     public string Sponsor { get; set; } 

     public virtual TrulyObservableCollection<Item> Items { get; private set; } = new TrulyObservableCollection<Item>(); 

} 
public class Item 
{ 
     public virtual Job Job { get; set; } 

     [Key] 
     public string ItemGUID { get; set; } = Guid.NewGuid().ToString(); 

     public int Order { get; set; } 
} 

我已經試過各種方法,但不是它的任何地方獲得,例如:

EntireCollection.SelectMany(o => o.Jobs).ToList().ForEach(d => d.Sponsor = d.Items.OrderBy(e => e.Order).ToList()); 

elem => elem.Jobs.OrderBy(
job => job.Items.OrderBy(
    item => item.Order 
) 

Argh! 
+0

你想在內部對它們進行排序嗎?你不能排序獲得財產? – MVCDS

+0

這是甚至編譯代碼?你如何設置'Sponsor',一個'string'屬性,用'List '? – Luizgrs

+1

另一點,'OrderBy'沒有訂購集合,它會「創建另一個集合」類型IEnumerable ,你應該重新考慮你的方法 – Luizgrs

回答

0

做到這一點最簡單的方法,但不建議。

jobCollection.ForEach((jobCol) => 
    { 
     jobCol.Jobs.ForEach((job) => 
     { 
      job.Items.OrderBy(item => item.Order); 
     }); 
     jobCol.Jobs.OrderBy((job) => job.Sponsor); 
    });