0
我有一個已知類型的對象的linq查詢,我需要基於對象的屬性對它進行排序。問題是我只知道運行時的屬性名稱和字符串。如何在LINQ to Entities(EF4.1)中進行OrderBy時,我只知道運行時的屬性名稱?
ex。
IQueryable<Thing> thing = from t in ctx.Things select t;
t.OrderBy(t => t.Name); // This would work if I knew the property at compile time...
t.OrderBy("Name asc"); // But this is what I really need! and it doesn't work.
有沒有辦法爲LINQ to Entities做到這一點?我使用實體框架4.1
看到這個問題http://stackoverflow.com/questions/307512/how-do-i-apply-orderby-on-an-iqueryable-using-a-string-column-name -within-a-gener#308561 –
謝謝,那應該可以做到。 – codemonkey