Esempio n. 1
0
        public async ValueTask <long> CountAsync <TEntity>(Expression <Func <TEntity, object> > condition = null) where TEntity : Entity, new()
        {
            var properties = typeof(TEntity).GetReadWriteProperties();
            var builder    = new QueryBuilder <TEntity>(Connector.Query, properties);

            if (condition != null)
            {
                builder.BuildWhereCount(condition.Body);
            }
            else
            {
                builder.BuildSelectCount();
            }

            var rowData = await SelectAsync(builder);

            return(Convert.ToInt64(rowData[0]?[0] ?? -1));
        }
Esempio n. 2
0
        public async Task <long> CountAsync <TEntity>(Expression <Func <TEntity, object> > condition = null) where TEntity : Entity, new()
        {
            var properties = typeof(TEntity).GetReadWriteProperties();
            var builder    = new QueryBuilder <TEntity>(connectorQuery, properties);
            var query      = condition != null?builder.BuildWhereCount(condition.Body) : builder.BuildSelectCount();

            using (var dataReader = await SelectAsync(query))
            {
                // Read the first row.
                await dataReader?.ReadAsync();

                // Return -1 if row data are null.
                return(Convert.ToInt64(dataReader?[0] ?? -1));
            }
        }