开发者

NHibernate Linq GroupBy multiple properties not working

I am using NHibernate 3 Alpha 2, and I am trying to do the number of posts per month

This is the code I came up with

List<PostMonthFrequency> monthFrequencies = _postRepository
    .FindAll()
    //.ToList() //<- if included works. however not desired
    .OrderByDescending(x => x.PublishedOn)
    .GroupBy(x => new {x.PublishedOn.Year, x.PublishedOn.Month})
    .Select(post => new PostMonthFrequency { Month = new DateTime(post.Key.Year, post.Key.Month, 01), Freqency = post.Count() }).ToList();

please not the FindAll will return the Session.Query()

I have also tried to remove the select

the error I get is:

NewExpression

Thats it.. I have got other开发者_StackOverflow社区 expression to work well with the select, so i do not think it is that, more to do with the Groupby

Thanks in advance

PS my temp fix

List<PostMonthFrequency> monthFrequencies = _postRepository
        .FindAll()
        .Select(x => x.PublishedOn)
        .ToList()
        .GroupBy(x => new { x.Year, x.Month })
        .Select(post => new PostMonthFrequency { Month = new DateTime(post.Key.Year, post.Key.Month, 01), Frequency = post.Count() })
        .ToList();


The best place to post NHibernate bugs is on the official mailing list here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜