Closed orochasamuel closed 5 years ago
Try this:
/// <summary>
/// Sums the values of a selected field for a given filtered collection of documents.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name = "filter" > A LINQ expression filter.</param>
/// <param name="selector">The field you want to sum.</param>
/// <param name="partitionKey">The partition key of your document, if any.</param>
public virtual async Task<decimal> SumByAsync<TDocument>(Expression<Func<TDocument, bool>> filter,
Expression<Func<TDocument, decimal>> selector,
string partitionKey = null)
where TDocument : IDocument
{
var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection<TDocument>() : GetCollection<TDocument>(partitionKey);
return await collection.AsQueryable()
.Where(filter)
.SumAsync(selector);
}
Hi @alexandre-spieser
I manage customer stock and would like to know how I get the sum of the quantities in the collection. Here is a more or less example:
My Class
My Service
To get the result is done the sum of all the moves but, the customer already has more than 20k entries. How can I improve this?
I considered using asynchronous but, I do not know very well. Is it the only way out?
Can you help me please?