Dynamic LINQ lets a .NET application construct LINQ query operations from strings at runtime. It is useful when a client must choose a sort column without a separate conditional branch for every column. section 5.4.2
Use it to add client-selected sorting to a paged query:
- Install System.Linq.Dynamic.Core through the Package Manager console or dotnet CLI. section 5.4.2
- Import System.Linq.Dynamic.Core so its string-based extension methods are available. section 5.4.2
- Pass the client’s sortColumn value to OrderBy(), then apply Skip() and Take() for paging. section 5.4.2
Paged board-game query
var query = _context.BoardGames .OrderBy(sortColumn) .Skip(pageIndex * pageSize) .Take(pageSize);
Validate or restrict sortColumn before passing it to OrderBy(). Unchecked input can cause runtime errors and may create SQL-injection risk if the ORM does not prevent it. section 5.4.2
