Entity framework query taking too much time to get number of records

Hi Team,
I am trying to run below .Net entity framework query , that is taking too long time to execute. It has lacs of records like more 900000+ records to get from MongoDB.
While converting to .ToList(), it is taking about to 2+ minutes to be execute and to get alll records. Find the C# code snippet here:
public IMongoCollection Message
return _database.GetCollection(_settings.Value.Message);
private readonly IMongoDbContext _context;

var msgsCounts = new List();
msgsCounts = _context.Message.AsQueryable(_aggregateOption)
.Where(x => x.utility_id == Convert.ToInt16(request.UtilityId)
&& x.IsCompleted == “0”
&& x.to_status != (int)StatusEnum.Delete_Read
&& x.to_status != (int)StatusEnum.Delete_Save_Read
&& x.to_status != (int)StatusEnum.Delete_Save_Unread
).GroupBy(s => new { s.message_group_id })
.Select(n => new MesssageCount
MessageGroupId = n.Key.message_group_id,
Count = n.Count()
I am thankful to all in advance.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.