title: How to use async all the way up to the top
body: <p>I have generic repository which has async methods <code>FindAsync</code>:</p>
  
  <pre><code>public class GenericRepository&lt;TEntity&gt; : IRepository&lt;TEntity&gt; where TEntity : class
  {
      private dynamic _context;
      private DbSet&lt;TEntity&gt; _dbSet;
  
      protected DbContext Context
      {
          get
          {
              if (_context == null)
              {
                  _context = DataContextFactory.GetDataContext();
              }
  
              return _context;
          }
      }
  
      protected DbSet&lt;TEntity&gt; DBSet
      {
          get
          {
              if (_dbSet == null)
              {
                  _dbSet = Context.Set&lt;TEntity&gt;();
              }
  
              return _dbSet;
          }
      }
  
      public virtual IQueryable&lt;TEntity&gt; GetQuery(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate = null, Func&lt;IQueryable&lt;TEntity&gt;, IOrderedQueryable&lt;TEntity&gt;&gt; orderExpression = null)
      {
          IQueryable&lt;TEntity&gt; qry = DBSet;
  
          if (predicate != null)
          {
              qry = qry.Where(predicate);
          }
  
          if (orderExpression != null)
          {
              return orderExpression(qry);
          }
  
          return qry;
      }
  
      public virtual IQueryable&lt;T&gt; GetQuery&lt;T&gt;(Expression&lt;Func&lt;T, bool&gt;&gt; predicate = null, Func&lt;IQueryable&lt;T&gt;, IOrderedQueryable&lt;T&gt;&gt; orderExpression = null) where T : class
      {
          DbSet&lt;T&gt; dbSet = Context.Set&lt;T&gt;();
          IQueryable&lt;T&gt; qry = dbSet;
  
          if (predicate != null)
          {
              qry = qry.Where(predicate);
          }
  
          if (orderExpression != null)
          {
              return orderExpression(qry);
          }
  
          return qry;
      }
  
      public virtual async Task&lt;IEnumerable&lt;TEntity&gt;&gt; FindAsync(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate, Func&lt;IQueryable&lt;TEntity&gt;, IOrderedQueryable&lt;TEntity&gt;&gt; orderExpression = null)
      {
          return await GetQuery(predicate, orderExpression).ToListAsync();
      }
  
      public virtual async Task&lt;IEnumerable&lt;T&gt;&gt; FindAsync&lt;T&gt;(Expression&lt;Func&lt;T, bool&gt;&gt; predicate, Func&lt;IQueryable&lt;T&gt;, IOrderedQueryable&lt;T&gt;&gt; orderExpression = null) where T : class
      {
          return await GetQuery&lt;T&gt;(predicate, orderExpression).ToListAsync();
      }
  }
  </code></pre>
  
  <p>And then I created a <code>CustomerRepository</code> which calls <code>FindAsync</code> from generic repo:</p>
  
  <pre><code>public class CustomerRepository
  {
      private readonly IRepository&lt;Customer&gt; _repo;
  
      /// &lt;summary&gt;
      /// Hookup dependencies
      /// &lt;/summary&gt;
      /// &lt;param name="repo"&gt;&lt;/param&gt;
      public CustomerRepository(IRepository&lt;Customer&gt; repo)
      {
          _repo = repo;
  
          //Disable entity proxy creation and  lazy loading.
          _repo.LazyLoadingEnabled(false);
      }
  
      /// &lt;summary&gt;
      /// Gets customer by id
      /// &lt;/summary&gt;
      /// &lt;param name="id"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public async Task&lt;Customer&gt; GetByIdAsync(Guid id)
      {
          return await _repo.FindAsync(p =&gt; p.Id == id).Result.SingleOrDefaultAsync();
      }
  }
  </code></pre>
  
  <p>The the problem that I have is that when I call <code>await _repo.FindAsync(p =&gt; p.Id == id).Result.SingleOrDefaultAsync();</code></p>
  
  <p>It says </p>
  
  <blockquote>
    <p>IEnumerable Customer does not contain a definition for SingleOrDefaultAsync. </p>
  </blockquote>
  
  <p>Anyone knows what I missed?</p>