I am getting a exception “Maximum allowed requests per session (30) is reached” etc..
I am trying to run a RavenDB query inside a “for loop” and I am wondering how I can get around doing this. The code is below.
using (var session = store.OpenSession())
{
var MovieList = session.Query<Movies>()
.ToList();
foreach (var movie in MovieList)
{
int NumByState = session.Query<Theaters>()
.Where(x => x.State == movie.State)
.Count();
string MovieName = movie.MovieName;
}
}
The records in the query are in the 100s and I need to run the count query inside of for loop, I cant see another way to run the query outside of the loop.. because I need to run this query for each of the items in the list. Thanks for the help.
This should solve your problem:
This will also be a lot faster than querying the DB hundreds of times – especially if the DB is accessed over a network.