views:

30

answers:

1

Is it possible to create a anoynmous count with nhibernate?

The below query throws the exception "No column *". I could of course add a column name, but I'd prefer not to, because if I do, I'll have to lookup column names for 95 tables...

NHibernate.Criterion.DetachedCriteria dcIsUniqueDomainname = NHibernate.Criterion.DetachedCriteria.For<nhDBapi.Tables.clsDomains>()
               .SetProjection(
                   NHibernate.Criterion.Projections.Count("*")
               )
               .Add(NHibernate.Criterion.Property.ForName("DomainID").Eq(strDomainID))
               .Add(NHibernate.Criterion.Property.ForName("DomainName").Eq(strDomainName)
           );
+4  A: 

You are Looking for Projections.RowCount().

Diego Mijelshon
Why does the type for NHibernate.Criterion.Projections.RowCount() need to be an int32? It fails when i use long (int64)... I mean there clearly can be more than 2^32 rows, can't there ? And it's kinda ironic when it returns a negative number because of overflow or whatever...
Quandary
There's `RowCountInt64` :-)
Diego Mijelshon
+1, and RowCount silently is int32... I wonder why it can't convert from int32 to long, the only problem should be vice-versa...
Quandary
You *can* convert the result of a RowCount projection to long by using Convert.ToInt64; it just doesn't make much sense.
Diego Mijelshon