✅ Is it possible to simplify this litedb query?
All I want is to get total count, count of not delivered, not read, not confirmed. Actually I don't is it possible to do in 1 query
var totalNotificationsCount = await _repository
.Query()
.Where(model => DateTimeOffset.Now <= model.ExpiresAt)
.Where(model => model.To
.Contains(operatorName))
.Count();
var notDeliveredNotificationsCount = await _repository
.Query()
.Where(model => DateTimeOffset.Now <= model.ExpiresAt)
.Where(model => model.To
.Contains(operatorName))
.Where(model => !model.MessageState.IsDelivered)
.Count();
var notReadNotificationsCount = await _repository
.Query()
.Where(model => DateTimeOffset.Now <= model.ExpiresAt)
.Where(model => model.To
.Contains(operatorName))
.Where( model => model.MessageState.IsDelivered
&& !model.MessageState.IsRead )
.Count();
var notConfirmedNotificationsCount = await _repository
.Query()
.Where(model => DateTimeOffset.Now <= model.ExpiresAt)
.Where(model => model.To
.Contains(operatorName))
.Where( model => model.MessageState.IsDelivered
&& model.MessageState.IsRead
&& !model.ConfirmationState.RequiresConfirmation)
.Count();var totalNotificationsCount = await _repository
.Query()
.Where(model => DateTimeOffset.Now <= model.ExpiresAt)
.Where(model => model.To
.Contains(operatorName))
.Count();
var notDeliveredNotificationsCount = await _repository
.Query()
.Where(model => DateTimeOffset.Now <= model.ExpiresAt)
.Where(model => model.To
.Contains(operatorName))
.Where(model => !model.MessageState.IsDelivered)
.Count();
var notReadNotificationsCount = await _repository
.Query()
.Where(model => DateTimeOffset.Now <= model.ExpiresAt)
.Where(model => model.To
.Contains(operatorName))
.Where( model => model.MessageState.IsDelivered
&& !model.MessageState.IsRead )
.Count();
var notConfirmedNotificationsCount = await _repository
.Query()
.Where(model => DateTimeOffset.Now <= model.ExpiresAt)
.Where(model => model.To
.Contains(operatorName))
.Where( model => model.MessageState.IsDelivered
&& model.MessageState.IsRead
&& !model.ConfirmationState.RequiresConfirmation)
.Count();