CameTooFar

A Nerd's False Positive.

Add GUID as primary key column in code-first migration

Last week, I was migrating an old ASP.NET MVC project and as part of that I decided to replace the identity column from auto-incremented numeric value to GUID values which looks more professional.

Below are the changes that you need to make to achieve this.

// in your model class.
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }


Run, Add-Migration command which generates your migration class and make below change:

// in your migration class.
AlterColumn("dbo.LoLChampionPickeds", "Id", c => c.Guid(nullable: false, identity: true, defaultValueSql: "newsequentialid()"));

That's it. Now do an Update-Database and your Id field will start using GUIDs.

Thanks.

HTTP Error 500.21 - Handler "BlockViewHandler" has a bad module "ManagedPipelineHandler"

Huu…!!!

As usual, jumped into another error when I tried to uploaded nopCommerce CMS kit and browsed for first time.

HTTP Error 500.21 - Internal Server Error
Handler "BlockViewHandler" has a bad module "ManagedPipelineHandler" in its module list

error_iis_nopcommerce_browse


I’s thinking, since I downloaded a ready-made kit, chances of errors should be zero!

Got it! As pre-requisites I installed ASP.NET MVC which had changed the ASP.NET version in my machine. As simple as that, you can fix it by running below command (with admin privilege).

%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i

solution_aspnet_regiis

Thanks.