Your code is very memory and computationally inefficient. There are two reasons why.
Your code seems to use a repository pattern. My answer is based on that assumption.
First, the most problematic part is that you get all entries and then you select the records that match the where condition. With this pattern, you scan all records two times, but there is no need for that. Try to add a where
clause in your parameters in your repository like below:
public async Task<List<T>> SelectAllAsync(Expression<Func<T, bool>>? filter = null)
{
IQueryable<T> query = dbSet;
if (filter != null)
{
// now you can put your where clause here
query = query.Where(filter);
}
return await query.ToListAsync();
}
And when calling it you can simply do the following:
IList<User> users = await _unitOfWork.UserRepository.SelectAllAsync(filter: x => x.Field == MyField);
Using this method, you only scan your database once and you don't need to filter the result again.
Second, if you use this User table a lot to get all the Users based on the IsActive Column, add an index for it since it is inefficient to call this code more than necessary.