4

I'm having some trouble excuting a query in fluent nhibernate. I have a table : Books with the following columns:

ID, NAME, YEAR, BOOK_TYPE, AUTHOR_ID

I want to excute the following sql query in Fluent NHibernate:

SELECT BOOK_TYPE, COUNT(*)
FROM BOOKS
GROUP BY BOOK_TYPE
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Golan Kiviti
  • 3,895
  • 7
  • 38
  • 63

1 Answers1

4

So called Fluent-NHibernate is just a mapping extension. To get data we need NHibernate built n querying features: ICriteria, QueryOver or even a LINQ.

Based on the documentation we can use projections for the above case, using the QueryOver API

16.6. QueryOver - Projections

The code snippet:

IList selection =
    session.QueryOver<Book>()
        .SelectList(list => list
            .Select(c => c.BooktType)
            .SelectCount(c => c.ID))
        .List<object[]>();
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335