예제 #1
0
        public void CountByQuery_NoQuery()
        {
            var countByQuery = new CountByQuery <CompositeIdSample>();
            var parameters   = new List <object>();
            var sql          = countByQuery.GetSql(null, parameters);

            Assert.AreEqual("SELECT COUNT(*) FROM `composite_id_table`;", sql);
        }
예제 #2
0
        public void CountByQuery()
        {
            var countByQuery = new CountByQuery <CompositeIdSample>();
            var parameters   = new List <object>();
            var sql          = countByQuery.GetSql(w => w.Equal(x => x.Id1, 5), parameters);

            Assert.AreEqual("SELECT COUNT(*) FROM `composite_id_table` WHERE (`Id1` = ?p0);", sql);
            Assert.AreEqual(5, parameters[0]);
        }
예제 #3
0
        public static long Count <T>(this IDbConnection connection, Action <IRestrictable <T> > restrictions = null)
            where T : class, new()
        {
            var countByQuery = new CountByQuery <T>();

            var parameters = new List <object>();
            var sql        = countByQuery.GetSql(restrictions, parameters);

            using (var command = connection.CreateCommand())
            {
                command.CommandText = sql;
                command.AttachPositionalParameters(parameters);
                return((long)command.ExecuteScalar());
            }
        }