public void CountQuery_ByType() { Prepare(); CountQuery cq = new CountQuery(typeof(Post)); int recordCount = (int)ActiveRecordMediator.ExecuteQuery(cq); Assert.AreEqual(3, recordCount); }
public void CountQuery_DetachedCriteria() { Prepare(); DetachedCriteria detachedCriteria = DetachedCriteria.For(typeof(Post)); detachedCriteria.Add(Expression.Eq("Category", "c")); CountQuery cq = new CountQuery(typeof(Post), detachedCriteria); int recordCount = (int)ActiveRecordMediator.ExecuteQuery(cq); Assert.AreEqual(2, recordCount); }
public void CountQuery_ByTypeAndCriteria() { Prepare(); ICriterion[] criterionArray = new ICriterion[] { Expression.Eq("Category", "c") }; CountQuery cq = new CountQuery(typeof(Post), criterionArray); int recordCount = (int)ActiveRecordMediator.ExecuteQuery(cq); Assert.AreEqual(2, recordCount); }
/// <summary> /// Returns the number of records of the specified /// type in the database /// </summary> /// <param name="targetType">The target type.</param> /// <param name="detachedCriteria">The criteria expression</param> /// <returns>The count result</returns> protected internal static int Count(Type targetType, DetachedCriteria detachedCriteria) { CountQuery query = new CountQuery(targetType, detachedCriteria); return (int)ExecuteQuery(query); }
/// <summary> /// Returns the number of records of the specified /// type in the database /// </summary> /// <param name="targetType">The target type.</param> /// <param name="criteria">The criteria expression</param> /// <returns>The count result</returns> protected internal static int Count(Type targetType, ICriterion[] criteria) { CountQuery query = new CountQuery(targetType, criteria); return (int) ExecuteQuery(query); }
/// <summary> /// Returns the number of records of the specified /// type in the database /// </summary> /// <example> /// <code> /// [ActiveRecord] /// public class User : ActiveRecordBase /// { /// ... /// /// public static int CountAllUsersLocked() /// { /// return Count(typeof(User), "IsLocked = ?", true); /// } /// } /// </code> /// </example> /// <param name="targetType">The target type.</param> /// <param name="filter">A sql where string i.e. Person=? and DOB > ?</param> /// <param name="args">Positional parameters for the filter string</param> /// <returns>The count result</returns> protected internal static int Count(Type targetType, string filter, params object[] args) { CountQuery query = new CountQuery(targetType, filter, args); return (int)ExecuteQuery(query); }
/// <summary> /// Returns the number of records of the specified /// type in the database /// </summary> /// <example> /// <code> /// [ActiveRecord] /// public class User : ActiveRecordBase /// { /// ... /// /// public static int CountAllUsers() /// { /// return Count(typeof(User)); /// } /// } /// </code> /// </example> /// <param name="targetType">The target type.</param> /// <returns>The count result</returns> protected internal static int Count(Type targetType) { CountQuery query = new CountQuery(targetType); return (int)ExecuteQuery(query); }
public void CountQuery_PositionalParameters() { Prepare(); object[] parameters = new object[] { "c" }; CountQuery cq = new CountQuery(typeof(Post), "Category = ?", parameters); int recordCount = (int)ActiveRecordMediator.ExecuteQuery(cq); Assert.AreEqual(2, recordCount); }