<p>I need to do the following for the purposes of paging a query in nHibernate:</p>

<pre><code>Select count(*) from 
(Select e.ID,e.Name from Object as e where...)
</code></pre>

<p>I have tried the following, </p>

<pre><code>select count(*) from Object e where e = (Select distinct e.ID,e.Name from ...)
</code></pre>

<p>and I get an nHibernate Exception saying I cannot convert Object to int32.</p>

<p>Any ideas on the required syntax?</p>

<p><strong>EDIT</strong></p>

<p>The Subquery uses a distinct clause, I cannot replace the e.ID,e.Name with <code>Count(*)</code> because <code>Count(*) distinct</code> is not a valid syntax, and <code>distinct count(*)</code> is meaningless.</p>

If you just need
```
e.Id
```
,
```
e.Name
```
:
```
select count(*) from Object where
```
.....