public static async ETTask<List<T>> QueryPage<T>(this DBComponent self, string filter, int pageIndex = 0, int pageSize = 5, string collection = null)
where T : Entity
{
var jsonFilterDefinition = new JsonFilterDefinition<T>(filter);
return await self.QueryPage<T>(jsonFilterDefinition, pageIndex, pageSize, collection);
}
public static async ETTask<List<T>> QueryPage<T>(this DBComponent self, FilterDefinition<T> filter, int pageIndex = 0, int pageSize = 5, string collection = null)
where T : Entity
{
using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomHelper.RandInt64() % DBComponent.TaskCount))
{
List<T> list = self.GetCollection<T>(collection)
.Find(filter)
.Sort(Builders<T>.Sort.Descending(x => x.Id))
.Skip(pageIndex * pageSize)
.Limit(pageSize)
.ToList();
return list;
}
}
public static async ETTask<List<T2>> Aggregate<T1, T2>(this DBComponent self, PipelineDefinition<T1, T2> pipeline, string collection = null)
where T1 : Entity where T2 : Entity
{
using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomHelper.RandInt64() % DBComponent.TaskCount))
{
IAsyncCursor<T2> cursor = await self.GetCollection<T1>(collection).AggregateAsync(pipeline);
return await cursor.ToListAsync();
}
}