Skip to content

Instantly share code, notes, and snippets.

@enisn
Created April 16, 2020 20:31
Show Gist options
  • Select an option

  • Save enisn/d87c5c4c8102711f3839c97be25d6278 to your computer and use it in GitHub Desktop.

Select an option

Save enisn/d87c5c4c8102711f3839c97be25d6278 to your computer and use it in GitHub Desktop.
Challenge #1 - Solution 2 - ProductsController.cs Fluent usage
public class ProductsController
{
private readonly MyDbContext context
public ProductsController(MyDbContext context)
{
this.context = context;
}
[HttpGet]
public async Task<IActionResult> GetAsync([FromQuery]ProductFilter filter)
{
var query = context.Products.ApplyFilter(filter); // <-- simple usage
// Fluent usage with any other LINQ method:
var queryOrdered = context.Products
.OrderBy(x => x.Stock)
.ApplyFilter(filter)
.Take(10);
return Ok(await query.ToListAsync())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment