2011-12-19 88 views
2

我在我的項目中使用Raven Db。我試着去訂購像文章OrderBy使用RavenDB-例外

list.OrderByDescending(x => x.Supporters.Sum(y=>y.Tokens)); 

,我得到這樣一個例外:

{"Unable to cast object of type 'System.Linq.Expressions.MethodCallExpressionN' to type 'System.Linq.Expressions.MemberExpression'."} 

型號看起來如下:

public class Idea 
{ 

    (...) 
    public IList<IdeaSupporter> Supporters { get; set; } 

} 

public class IdeaSupporter 
{ 
    (...) 
    public int Tokens { get; set; } 
} 

什麼我錯了嗎? 感謝您的幫助。

+0

如何列表中聲明? – 2011-12-19 14:56:37

回答

1

不能排序的計算,但你可以這樣定義的索引:

from idea in docs.Ideas 
select new 
{ 
    SumOfSupportersTokens = idea.Supporters.Sum(x=>x.Tokens) 
} 

然後排序上SumOfSupportersTokens