Blazor Dapper Code Generator

As mentioned earlier in 'Getting Started', Alan Simpson has a great YouTube series of videos on how to use Dapper with Blazor.  Better still he has created a small application that will do most of the hard work creating the SQL stored procedures and C# code for the CRUD operations.  We are going to take advantage of Alan's Blazor-Dapper-Code-Generator.

Blazor-Dapper-Code-Generator

To get the code generator open browser and go to https://github.com/AlanSimpsonMe/ Select:

  • Repositories
  • Blazor-Dapper-Code-Generator
  • Code
  • Download zip file and save somewhere convenient (Desktop would be OK)
  • Close the web browser
  • Go to the downloaded file and Extract All.
  • Go to the extracted files and find 'Blazor-Dapper-Code-Generator-master.sln' and open with Visual Studio
  • Run the application - it will need to be run for each table, in our case once for the Countries table, and again for the Cities table.
  • Enter the 'Namespace' - this is name of the project (BlazorCountries)
  • Paste the 'Create Table' SQL (shown below) into the large textbox and click the 'Go' button.
CREATE TABLE [dbo].[Countries](
	[CountryId] [int] IDENTITY(1,1) NOT NULL,
	[CountryName] [varchar](50) NULL,

The code generator will produce a lot of code, together with instructions.  Copy and paste all the generated code to Notepad++.  (It just makes things a little simpler.)

  • Close the Code Generator to clear the generated code.  Re-open the Code Generator and repeat with the Create Table SQL for Cities, again copying and pasting all code to a separate file in Notepad++.
CREATE TABLE [dbo].[Cities](
	[CityId] [int] IDENTITY(1,1) NOT NULL,
	[CityName] [varchar](50) NULL,
	[CountryId] [int] NULL,
	[CityPopulation] [int] NULL,

Be aware that Alan's Countries table is not the same as our example and so it probably won't be possible to follow the generated code example exactly unless you substitute Alan's table definition - but it would be a worthwhile example anyway.

YouTube Video

Blazor + Syncfusion + Dapper: Part 3