protected override async Task <TEntity?> DoGetAsync(EFRepositoryQuery <TEntity> query, CancellationToken cancellationToken = default) { var dbQuery = query.BuildQuery(); var item = await ExecuteDbContextOperationAsync( () => AddIncludes(dbQuery).FirstOrDefaultAsync(cancellationToken), cancellationToken); if (item != null) { await AfterLoadAsync(item, cancellationToken); } return(item); }
public static async Task <(T[] items, int itemsCount)> GetAllAsync <T>(this EFRepositoryQuery <T> query)
protected override Task <int> DoCountAsync(EFRepositoryQuery <TEntity> query, CancellationToken cancellationToken = default) { return(ExecuteDbContextOperationAsync(() => query.BuildQuery().CountAsync(cancellationToken), cancellationToken)); }
protected override async Task <(TEntity[] items, bool needCount)> DoGetAllAsync(EFRepositoryQuery <TEntity> query, CancellationToken cancellationToken = default) { var dbQuery = query.BuildQuery(); var needCount = false; if (query.Offset != null) { dbQuery = dbQuery.Skip(query.Offset.Value); needCount = true; } if (query.Limit != null) { dbQuery = dbQuery.Take(query.Limit.Value); needCount = true; } var result = await ExecuteDbContextOperationAsync( () => AddIncludes(dbQuery).ToArrayAsync(cancellationToken), cancellationToken); return(result, needCount); }