{"action":"created","issue":{"url":"https://api.github.com/repos/CollaboratingPlatypus/PetaPoco/issues/99","labels_url":"https://api.github.com/repos/CollaboratingPlatypus/PetaPoco/issues/99/labels{/name}","comments_url":"https://api.github.com/repos/CollaboratingPlatypus/PetaPoco/issues/99/comments","events_url":"https://api.github.com/repos/CollaboratingPlatypus/PetaPoco/issues/99/events","html_url":"https://github.com/CollaboratingPlatypus/PetaPoco/issues/99","id":3284121,"number":99,"title":"Helper method \"Count<T>()\" easily added","user":{"login":"genez","id":324113,"avatar_url":"https://avatars.githubusercontent.com/u/324113?v=3","gravatar_id":"","url":"https://api.github.com/users/genez","html_url":"https://github.com/genez","followers_url":"https://api.github.com/users/genez/followers","following_url":"https://api.github.com/users/genez/following{/other_user}","gists_url":"https://api.github.com/users/genez/gists{/gist_id}","starred_url":"https://api.github.com/users/genez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genez/subscriptions","organizations_url":"https://api.github.com/users/genez/orgs","repos_url":"https://api.github.com/users/genez/repos","events_url":"https://api.github.com/users/genez/events{/privacy}","received_events_url":"https://api.github.com/users/genez/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2012-02-19T10:53:20Z","updated_at":"2015-12-04T02:58:29Z","closed_at":null,"body":"I think it would be easy to implement a Count<T>() method and it would be helpful - here is my code, tested and working\r\n\r\n\r\n        public int Count<T>(string sql, params object[] args)\r\n        {\r\n            if (EnableAutoSelect)\r\n                sql = AddSelectClause<T>(sql);\r\n\r\n            // Split the SQL into the bits we need\r\n            string sqlSelectRemoved, sqlOrderBy, sqlCount;\r\n            if (!SplitSqlForPaging(sql, out sqlCount, out sqlSelectRemoved, out sqlOrderBy))\r\n                throw new Exception(\"Unable to parse SQL statement for count query\");\r\n\r\n            OpenSharedConnection();\r\n            try\r\n            {\r\n                using (var cmd = CreateCommand(_sharedConnection, sqlCount, args))\r\n                {\r\n                    int count = 0;\r\n\r\n                    try\r\n                    {\r\n                        count = (int)cmd.ExecuteScalar();\r\n                        OnExecutedCommand(cmd);\r\n                    }\r\n                    catch (Exception x)\r\n                    {\r\n                        OnException(x);\r\n                        throw;\r\n                    }\r\n\r\n                    return count;\r\n                }\r\n            }\r\n            finally\r\n            {\r\n                CloseSharedConnection();\r\n            }\r\n        }\r\n\r\n        public int Count<T>(PetaPoco.Sql sql)\r\n        {\r\n            return Count<T>(sql.SQL, sql.Arguments);\r\n        }\r\n"},"comment":{"url":"https://api.github.com/repos/CollaboratingPlatypus/PetaPoco/issues/comments/161858206","html_url":"https://github.com/CollaboratingPlatypus/PetaPoco/issues/99#issuecomment-161858206","issue_url":"https://api.github.com/repos/CollaboratingPlatypus/PetaPoco/issues/99","id":161858206,"user":{"login":"pleb","id":595869,"avatar_url":"https://avatars.githubusercontent.com/u/595869?v=3","gravatar_id":"","url":"https://api.github.com/users/pleb","html_url":"https://github.com/pleb","followers_url":"https://api.github.com/users/pleb/followers","following_url":"https://api.github.com/users/pleb/following{/other_user}","gists_url":"https://api.github.com/users/pleb/gists{/gist_id}","starred_url":"https://api.github.com/users/pleb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleb/subscriptions","organizations_url":"https://api.github.com/users/pleb/orgs","repos_url":"https://api.github.com/users/pleb/repos","events_url":"https://api.github.com/users/pleb/events{/privacy}","received_events_url":"https://api.github.com/users/pleb/received_events","type":"User","site_admin":false},"created_at":"2015-12-04T02:58:29Z","updated_at":"2015-12-04T02:58:29Z","body":"Thanks for the suggestion. If you'd like to see this is PetaPoco, please send a PR. Read more about contributing here https://guides.github.com/activities/contributing-to-open-source/"}}