Hibernating Rhinos Ltd
Oren Eini l CEO l Mobile: + 972-52-548-6969
Office: +972-4-622-7811 l Fax: +972-153-4-622-7811
--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public static async Task<int> BatchUpdateAsync<T>(this IAsyncDocumentSession session, Expression<Func<T, bool>> expression, Action<IList<T>> action)
{
session.Advanced.MaxNumberOfRequestsPerSession = int.MaxValue;
RavenQueryStatistics stats = null;
int start = 0;
while (true)
{
if (stats != null && stats.TotalResults <= start)
break;
var query = session.Query<T>()
.Where(expression)
.Take(1024)
.Skip(start);
if (stats == null)
{
query = query.Statistics(out stats);
}
var entities = await query.ToListAsync();
if (entities.Count == 0)
break;
start += entities.Count;
action(entities);
await session.SaveChangesAsync();
}
return stats.TotalResults;
}
var total = await session.BatchUpdateAsync<Prediction>(x => x.Status == PredictionStatus.Open, predictions =>
{
foreach (var prediction in predictions)
{
// do some updates on any of Prediction properties
prediction.SetLastStockQuote(stockQuote);
}
});