Blazor: Modifying header meta and link elements

When creating web applications, we all try to create good SEO tags in the header of each page. Modifying the meta tags based on page content is a standard practice. In Blazor, this is not obvious as the _host.cshtml is rendered before the Blazor execution pipeline.

There was a tag extension in the preview of Blazor 5 which didn’t make it into the release and there are no news if this is continued or not (just a note from a program manager that this didn’t make it into the release) … so I guess this will be solved across the board in next release …. ? 🙂

Fortunately we have Toolbelt.Blazor.HeadElement (https://github.com/jsakamoto/Toolbelt.Blazor.HeadElement/)

This works nicely if you make sure to use server prerendering as explained in the documentation. The default setup options result in (at least) the Facebook screen scraping does not collect the updated title and meta elements, but only the original ones (which are the site static default ones).

This is all fixed with ….

 app.UseHeadElementServerPrerendering();

…. as described in the documentation. Check out: https://golf80.com/Rounds/33957

EF6 core – reset migrations during development

In development and while testing various things in EF6 core – I tend to end up with a lot of migration garbage which occasionally I have to take out. This is how it’s done #notetoself

  1. Delete all *. cs files in the Migrations Folder.
  2. Delete the _MigrationHistory Table in the Database
  3. Delete all database tables subject to the migration (take care of the data 🙂 ).
  4. Run dotnet ef migrations add Reset
  5. Run dotnet ef migrations list to get the full name of last migration
  6. Run dotnet ef database update [migration-name]

#notetoself

EF6 core – load grandchildren in query – the key is ThenLoad

Working with entity: Tournament

Which has children: TRound with Course as entity that needs to be loaded based on Id ( as each golf round is played on a Course 🙂 )

ctx.Tournaments.Include(c => c.Trounds).ThenInclude(c => c.Course)

Took me a while to figure out why ctx.Tournaments.Include(c => c.Trounds.Select(c => c.Course)) stopped working, but it is a (good) core thingy.