Exemple #1
0
        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);
        }
Exemple #2
0
 public static async Task <(T[] items, int itemsCount)> GetAllAsync <T>(this EFRepositoryQuery <T> query)
Exemple #3
0
 protected override Task <int> DoCountAsync(EFRepositoryQuery <TEntity> query,
                                            CancellationToken cancellationToken = default)
 {
     return(ExecuteDbContextOperationAsync(() => query.BuildQuery().CountAsync(cancellationToken),
                                           cancellationToken));
 }
Exemple #4
0
        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);
        }