Have you try to batch your data?
for example:
int batchSize = 1000;
var customers = new List<Customer>();
for (int i = 0; i < ids.Count; i += batchSize)
{
var batchIds = ids.Skip(i).Take(batchSize).ToList();
customers.AddRange(dbContext.Customers.Where(c => batchIds.Contains(c.Id)).ToList());
}
or you can make temporary table to store your data and then proceed to your actual table.