Esempio n. 1
0
        public virtual long Count(IEnumerable <string> tags = null, IEnumerable <Criteria> criterias = null)
        {
            if (Options.EnableLogging)
            {
                Log.Debug($"{TableName} count: tags={tags?.Join("||")}");
            }

            using (var conn = CreateConnection())
            {
                var sql = new StringBuilder($@"{SqlBuilder.BuildUseDatabase(Options.DatabaseName)} SELECT COUNT(*) FROM {TableName} WHERE [id]>0");
                foreach (var t in tags.NullToEmpty())
                {
                    sql.Append(SqlBuilder.BuildTagSelect(t));
                }
                foreach (var c in criterias.NullToEmpty())
                {
                    sql.Append(SqlBuilder.BuildCriteriaSelect(IndexMaps, c));
                }
                //var sql = $@"SELECT COUNT(*) FROM {TableName} WHERE [id]>0";
                //tags.NullToEmpty().ForEach(t => sql += SqlBuilder.BuildTagSelect(t));
                //criterias.NullToEmpty().ForEach(c => sql += SqlBuilder.BuildCriteriaSelect(IndexMaps, c));
                conn.Open();
                return(conn.Query <int>(sql.ToString()).SingleOrDefault());
            }
        }