I have case which I have a set of users some are bot and some are not. I also use pagination with a size of 9. I want to take 5 non bot users and 4 bot users in a page. I am listing users with this lines of code .
var list = await _userRepository
.ListGeneric(filterBy: finalExpression,
orderBy: r => r.CreatedAt,
thenBy: r => String.IsNullOrEmpty(r.PP) == false &&
r.PP != "somestringvalue" &&
r.PP != "somestringvalue",
skip: skip,
limit: paginationQuary.PageSize,
cancellationToken);
At user repository ListGeneric looks like this.
public Task<List<User>> ListGeneric<TOrder, TThen>(Expression<Func<User, bool>> filterBy, Expression<Func<User, TOrder>> orderBy, Expression<Func<User, TThen>> thenBy, int skip, int limit, CancellationToken cancellationToken = default)
{
return GetQuery(filterBy)
.OrderByDescending(thenBy)
.ThenByDescending(orderBy)
.Skip(skip)
.Take(limit)
.ToListAsync(cancellationToken: cancellationToken);
}
And at last User model is like this
public class User : DbBase
{
public string Name { get; set; }
public string Surname { get; set; }
public string SearchName { get; set; }
public string Email { get; set; }
public string MobilePhoneCode { get; set; }
public string MobilePhone { get; set; }
public string PP { get; set; }
public bool IsBot { get; set; }
}
I think joining IsBot ones and not IsBot ones seperately but is there a better approach in this case? Much appreciated for the help.