Skip to main content

Loading data into BindingSource, grid and lookups

This example is the Support Desk ticket browser. TicketQueryService.SearchTicketsAsync composes AsNoTracking, one Where per filter, CountAsync, OrderByDescending, Skip/Take and a Select into TicketListItem, and the materialised list goes into ticketBindingSource, which the grid is bound to.

Run it

cd "LearnWisej-Samples/Data Binding with EF Core Course/Module 3/SupportDesk.Web"
dotnet run -f net10.0 --urls http://localhost:5403

In Development the host migrates and seeds the local SQLite file at start. The EF Core command log is on in appsettings.Development.json, so every statement appears in the console. Tests: dotnet test SupportDesk.Tests.

What to try

The page is the ticket browser: searchTextBox, statusComboBox, customerComboBox, searchButton, ticketsDataGridView (through ticketBindingSource), statusLabel, prevPageButton, nextPageButton.

  • Open the page: the lookups load first, then the first page: Showing 50 of 312 tickets · page 1 of 7 · page size 50.
  • Search with text, a status and/or a customer: the page index resets; the console shows exactly two statements, a COUNT and a paged SELECT … LIMIT @p OFFSET @p (SQLite renders paging as LIMIT/OFFSET).
  • Next page / Previous page: one new query each; Previous is disabled on page 1, Next on the last page.
  • No matches: No tickets match these filters.
  • Database failure: a friendly AlertBox, Tickets could not be loaded, and the buttons come back, so the next Search simply runs again.