MVC and Entity Framework scaffolding is powerful, but I prefer to know what actually happens before accepting generated code. The code generated to update an entity when an edit has been done looked interesting, so I decided to have a closer look at it. When an edit is done to an entity, the data is… Continue reading Dissecting MVC Scaffolded Code for EF Updates
Tag: SQL
Idempotent DB Update Scripts
An idempotent function gives the same result even if it is applied several times. That is exactly how a database update script should behave. It shouldn’t matter if it is run on or multiple times. The result should be the same. A database update script should be made to first check the state of the… Continue reading Idempotent DB Update Scripts
Null Sematics in LINQ’s Sum
C# LINQ code is not always executed as C# code. With LINQ-to-SQL or Entity Framework it is translated into SQL instead. This can bring unpleasant surprises when things that can’t happen do happen. One day when you’re deep in the zone coding a marketing specialist shows up with a haunted look because the CEO wants… Continue reading Null Sematics in LINQ’s Sum
Database Table Primary Keys
When designing a database, I have a standard of always creating a clustered primary key in each table of type INT IDENTITY(1,1) NOT NULL. CREATE TABLE Cars( ID INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_Cars PRIMARY KEY CLUSTERED, Brand NVARCHAR(20) NOT NULL, RegistrationNumber NVARCHAR(10) NOT NULL, MadeIn NVARCHAR(20) NOT NULL )CREATE TABLE Cars( ID INT IDENTITY(1,1)… Continue reading Database Table Primary Keys
Transaction Safety for Manual SQL Updates
When maintaining a system that is in production there are often issues that need to be solved by running custom SQL scripts directly in the production database. There can be different reasons for this: Updating a lookup table to add a new option to dropdown boxes, where there is no user interface for handling the… Continue reading Transaction Safety for Manual SQL Updates