public void RowsCount() { IRowsCounter rc = new QueryRowsCounter("select count(*) from Foo"); using (ISession s = OpenSession()) { Assert.AreEqual(totalFoo, rc.GetRowsCount(s)); } }
public void RowsCountUsingParameters() { IDetachedQuery dq = new DetachedQuery("select count(*) from Foo f where f.Name like :p1").SetString("p1", "%1_"); IRowsCounter rc = new QueryRowsCounter(dq); using (ISession s = OpenSession()) { Assert.AreEqual(5, rc.GetRowsCount(s)); } }
/// <summary> /// Transform an gigen <see cref="DetachedQuery"/> (HQL query) to it's rows count. /// </summary> /// <param name="query">The given <see cref="DetachedQuery"/>.</param> /// <returns> /// A <see cref="QueryRowsCounter"/> based on <paramref name="query"/>, with row count, using /// same parameters and it's values. /// </returns> /// <exception cref="HibernateException">When the query don't start with 'from' clause.</exception> /// <remarks> /// Take care to the query; it can't contain any other clause than "from" and "where". /// Set the parameters and it's values, of <paramref name="query"/> befor call this method. /// </remarks> public static QueryRowsCounter Transforming(DetachedQuery query) { if (!query.Hql.StartsWith("from", StringComparison.InvariantCultureIgnoreCase)) { throw new HibernateException( string.Format( "Can't trasform the HQL to it's counter, the query must start with 'from' clause:{0}", query.Hql)); } QueryRowsCounter result = new QueryRowsCounter("select count(*) " + query.Hql); result.CopyParametersFrom(query); return result; }
/// <summary> /// Transform an gigen <see cref="DetachedQuery"/> (HQL query) to it's rows count. /// </summary> /// <param name="query">The given <see cref="DetachedQuery"/>.</param> /// <returns> /// A <see cref="QueryRowsCounter"/> based on <paramref name="query"/>, with row count, using /// same parameters and it's values. /// </returns> /// <exception cref="HibernateException">When the query don't start with 'from' clause.</exception> /// <remarks> /// Take care to the query; it can't contain any other clause than "from" and "where". /// Set the parameters and it's values, of <paramref name="query"/> befor call this method. /// </remarks> public static QueryRowsCounter Transforming(DetachedQuery query) { if (!query.Hql.StartsWith("from", StringComparison.InvariantCultureIgnoreCase)) { throw new HibernateException( string.Format( "Can't trasform the HQL to it's counter, the query must start with 'from' clause:{0}", query.Hql)); } QueryRowsCounter result = new QueryRowsCounter("select count(*) " + query.Hql); result.CopyParametersFrom(query); return(result); }