NotSupportedException on IQuery's Enumerable w

2019-07-28 04:07发布

问题:

when trying to use the Enumerable method on a named query, with a Stateless session, as shown in the example at:

http://www.nhforge.org/doc/nh/en/#batch-statelesssession

i am seeing a NotSupportedException. the stack trace is as below:

System.NotSupportedException: Specified method is not supported.
at NHibernate.Impl.StatelessSessionImpl.Enumerable(String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.Enumerable()

here is a snippet of my code:

IStatelessSession statelessSession = sessionFactory.OpenStatelessSession();
var fileLines = statelessSession.GetNamedQuery("GetLinesByFileId")
.SetInt32("FileIdInput", fileId).Enumerable<FileLineEntity>();

the named query, GetLinesByFileId is defined in the hbm as below:

<query name="GetLinesByFileId" cacheable="false" read-only="true">
    <![CDATA[
        from FileLineEntity lineItem where lineItem.FileId=:FileIdInput 
      ]]>
  </query>

any suggestions on what i maybe missing here?

回答1:

The doc is wrong. Also, by looking at it you can tell it's copied from Hibernate (Java).

Use the List method instead.