locked
dbSet.Where question RRS feed

  • Question

  • User-1104215994 posted

    Hello there,

    Can I convert this;

    var gameBankResult = await (context.GameBanks.Where(g => g.productCode == initiate.productCode)
                    .Where(l => l.referenceId == null)
                    ).ToListAsync();

    into async this?

    public virtual IQueryable<TEntity> GetManyQueryable(Func<TEntity, bool> where)
            {
                return dbSet.Where(where).AsQueryable();
            }

    Best Regards.

    Wednesday, July 3, 2019 11:57 AM

Answers

  • User-1104215994 posted

    Here is the answer, someone may need.

    public virtual async Task<List<TEntity>> GetGamesAsync(
    Expression<Func<TEntity, bool>> where)
    {
    return await dbSet.Where(where).ToListAsync();
    }

    How I am calling

     var gameBankResult =
                        await _unitOfWork.GameBankRepository.GetGamesAsync(g =>
                            g.productCode == requestDto.productCode && g.referenceId == null);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 4, 2019 5:40 AM

All replies

  • User475983607 posted

    These are two very different constructs.  The first code block actually executes a query and hence the async.  The second is a potential query.  Add the async keyword when you are ready to execute the query.

    The openly published documentation covers LINQ fundamentals.

    Wednesday, July 3, 2019 12:01 PM
  • User-1104215994 posted

    Here is the answer, someone may need.

    public virtual async Task<List<TEntity>> GetGamesAsync(
    Expression<Func<TEntity, bool>> where)
    {
    return await dbSet.Where(where).ToListAsync();
    }

    How I am calling

     var gameBankResult =
                        await _unitOfWork.GameBankRepository.GetGamesAsync(g =>
                            g.productCode == requestDto.productCode && g.referenceId == null);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 4, 2019 5:40 AM