Hi ,
I am working with RavenDB for our project requirement.
There are a particular use case here as follows where we have written a Map Reduce index on the data to get the travel count per user account.
AccountId TravelCount
TestA 5
TestB 4
TestC 3
TestD 6
TestE 2
TestF 1
Now we have a requirement to show the top 2 travel count [i.e. greater than current user travel count] and bottom 2 [i.e. lesser than current user travel count] travel count based on the user account id.
We are trying to perform this whole operation into a single query in Asynchronously Web API.
public async Task<IList<IEnumerable<UserDataRountCount>>> GetUserRouteCount(string accountId)
{
return await Session
.Query<UserDataRountCount>("CountRouteByAccount", true)
.Customize(c => c.WaitForNonStaleResultsAsOfNow())
.Where(q => q.AccountId == accountId)
.Select
(p=>
Session
.Query<UserDataRountCount>("CountRouteByAccount", true)
.Where(r=> r.RountCount > p.RountCount)
.OrderBy(l=> l.RountCount)
.Take(1)
.ToList()
.Union
(
Session
.Query<UserDataRountCount>("CountRouteByAccount", true)
.Where(s => s.RountCount <= p.RountCount)
.OrderBy(k => k.RountCount)
.Take(1)
.ToList()
)
)
.ToListAsync();
}
It always show error that cannot perform sync query in async function.
Could you please have a look and suggest the best possible way to do this.
Thanks in advance,
Arup