2011-12-19 45 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