Created
April 16, 2020 20:31
-
-
Save enisn/d87c5c4c8102711f3839c97be25d6278 to your computer and use it in GitHub Desktop.
Challenge #1 - Solution 2 - ProductsController.cs Fluent usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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