title: Mapping business logic in Web API async
body: <p>I am creating a Web API asp.net 5 using EF 6 without any repository, UOW, Facade in top of EF. 
  I do want to apply business rules in Service layer keeping async (at least the return of every API method) applying business logic
  and make some conversions between Product to ProductVO</p>
  
  <p>Product Service</p>
  
  <pre><code>public async Task&lt;ProductVO&gt; getProductVO(int id)
      {
          using (_context = new OnlineShopContext())
          {
              EntityMapper mapper = new EntityMapper();
              Product product = await GetAsync(id);
              Task&lt;Supplier&gt; supplier = _context.Suppliers.SingleOrDefaultAsync(s =&gt; s.ID == product.Supplier.ID);
              Task&lt;Category&gt; category = _context.Categories.SingleOrDefaultAsync(c =&gt; c.ID == product.Category.ID);
              return await mapper.map(product, await supplier, await category);
          }
      }
  </code></pre>
  
  <p>Product service needs to wait for product for finding supplier and category. (This is a very simple case, but think about calling a SP, or there is a locking
  on supplier or category, handling exceptions?)</p>
  
  <p>Entity mapper</p>
  
  <pre><code>public Task&lt;ProductVO&gt; map(Product product, Supplier supplier, Category category)
      {
          ProductVO productVo = new ProductVO(id: product.ID, productName: product.Name, supplierId: supplier.ID,
                  supplierName: supplier.Name, categoryId: category.ID, categoryName: category.Name,
                  thumbImageName: product.ThumbImageName, imageName: product.ImageName, price: product.Price
          );
          return new Task&lt;ProductVo&gt;productVo;
      }
  </code></pre>
  
  <p>Think about a more complex case of evaluating a list of Products until matching a business rule without waiting for the whole list from the db to start 
  matching an specific requirement. Similar to my AsyncEx library with OrderByCompletion option.</p>
  
  <p>Thank you</p>