Using LocalDB for Integration/Unit Tests

Long did I hold this perception that integration tests are hard. With EF core, they are actually really easy. Instead of using SQL Sever, we can substitute with LocalDB. Run this before running the tests and you'll have your db setup. After calling EnsureCreated you can add things into the database.

ASP.NET Core - Optimisation Hacks

Google has developed a tool called PageSpeed. It highlighted couple of quick wins I could do to improve website's loading time. Website loading times are one of the most deceptive metrics to measure during development. Website development is frequently done on a local machine when download times are neligiable. It is only once the website ... Read more ASP.NET Core - Optimisation Hacks

ConcurrentDictionary - Get Snapshot and Clear - Fun C# Code #2

Recently, I was asked to write a 'real-time' calculator and the output value was to be stored in Redis. For legacy reasons, it also had to be stored in the database though, only the latest value had to be kept. As the calculator was spewing values, they were stored in a ConcurrentDictionary. When the timer ... Read more ConcurrentDictionary - Get Snapshot and Clear - Fun C# Code #2

Fun C# Code #1 - Infinite Delay (until cancelled)

I came across this code when reading 'Concurrency in C# Cookbook' by Stephen Cleary. Did you know you can have an infinite Task.Delay without loops?

Obviously, there isn't much point in spinning a task that litterally will do nothing. You can use a CancellationToken to cancel the task.

No point. It's just one ... Read more Fun C# Code #1 - Infinite Delay (until cancelled)

Adding Quartz to your ASP.NET Core

This is a ready made example of how to add a scheduled job to your ASP.NET core web application:

In your Program.cs

How to regain space after dropping columns in SQL Server

I hit an annoying issue today. I wanted to regain space after I dropped several columns in a table. When I run the famous query from StackOverflow:

I got a set of numbers which were the same before and after the removal has

There is, however, a potential issue with this approach if ... Read more How to regain space after dropping columns in SQL Server

The ALTER TABLE statement conflicted with the FOREIGN KEY constrain

I've been trying to apply a new migration and I was getting the following error: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.Parent_dbo.Childs_ChildId". The conflict occurred in database "parents_db", table "dbo.Childs", column 'ChildId'. In my case, the table contained data. Therefore, either you have to assign a default value, set it as ... Read more The ALTER TABLE statement conflicted with the FOREIGN KEY constrain