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