Explicit and Implicit conversion

Explicit operator While digging into some legacy code at work, I found ‘explicit operator‘ is used in some classes. Explicit operator allow casting (or conversion) from one class to another. If you have 2 different classes, you cannot cast one to another, you’ll get a compile error. i.e   Now, if you add explicit operator, you can … [Read more…]

Insert multiple data in a single insert statement – SQL Server 2014

So often when people insert initial data into the database (whether via migration or post deployment scripts), they repeat the ‘insert into’ for each data value. i.e

However there is a quicker way to insert without having to repeat the ‘insert into’ statement


Excluding certain properties when asserting objects with FluentAssertion

It’s very common that we assert if two objects are equivalent in unit tests. Using FluentAssertion, this looks like the following

However, there are times where you want to exclude certain properties when comparing objects. This might be because the value of the property cannot be predicted or you just don’t want to include … [Read more…]

Json.net serialisation issue when returning Entity Framework models in Web API

It’s very typical for Entity Framework models to have circular references. For example:

This, however, will cause serialisation error when returning these EF models in Web API controller because it detects that there are circular references. The json serialiser does not know how to handle circular reference.

There are a few solutions to … [Read more…]

Code review, why it matters

This is the first post in my series of blog posts about some of the bad codes or bad practices I’ve come across. Note that this is my personal opinion and some of the things I mention could be debatable. Post 1: Code review, why it matters Post 2: Not including JS, CSS and static content … [Read more…]