开发者

QueryOver with Select and OrderBy in NHibernate

I am wondering how do I order a group of results after a select with QueryOver. My query is the following:

CurrentSession.QueryOver<Book>()
    .Where(b => b.Author.Name = "SimpleName")
    .Select(Projections.Distin开发者_Go百科ct(Projections.Property<Book>(b => b.Genre)))
    .OrderBy<Genre>(g => g.Name) // this extension does not exist! How do I order for a Genre?
    .List<Genre>()

How can I do?


Your query won't work to begin with. You first of all need to do a join, then you can do your order by and select projections.

Author author = null;
Genre genre = null;
CurrentSession.QueryOver<Book>()
     .JoinAlias(b => b.Author, author)
     .JoinAlias(b => b.Genre, genre)
     .Where(() => author.Name == "SimpleName")
     .OrderBy(() => genre.Name)
     .Select(Projections.Distinct(Projections.Property<Book>(b => b.Genre)))
     .List<Genre>();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜