Skip to content

Blog

Little SQL Server Tricks: Escape _ in LIKE Queries

If you search for a value with an _ in the name, you learn something new about SQL Server, but end up with a result that does not match your expectation:

SELECT * FROM [dbo].[DatabaseLog]
WHERE Object LIKE '%_%'

If we run this query, we do not get back everything with an _ in it. Instead, we get back everything. How is that possible? The _ is a placeholder that stands for any character, what gives us back every row that has any character anywhere in the column we search for. That is most likely not what we try to do.

Repository Aliases in GitHub Desktop

If you have two repositories with the same name in GitHub Desktop, you have a hard time to figure out which one is which:

The two projects look the same.

This can happen when we need to work on a fork of the project and the original one at the same time or when we have a backup in a different folder where we need to check something but do not want to do the work in our main repository.

The Core Folder Anti-Pattern

There is an interesting pattern that you can find in many projects, that usually starts with a good idea and turns into a dump in no time: the core folder. You start with an application and think about the core business, the important stuff. So, you go on and create a core folder. Here is now the place for the important stuff, right? No. Here is the start of your mess that from now on only grows.

Windows 11 Installer Stuck at 42% - Now What?

There is an annoying bug in the Windows 11 Installer that catches me way too often. If you select something different than the pre-selected values in the first screen for the language options, the installer starts but then stays forever at this progress level:

42%

How to Back up Your GitHub Repositories

Many developers use GitHub to share their code. It is convenient, offers a lot of features and works without any noticeable problems for years. Did you ever thought on creating a backup for your repositories?

Git helps us to ignore that task a bit. With every git clone we create a full copy of the whole repository, what by all means is a backup. Why should we then do some extra work to get another backup? It is true that Git creates a copy. But do you have a current copy of all your repositories on GitHub somewhere easy to find? Not only the few repositories you worked on in the last month, but everything you have on GitHub up to its newest commit. Probably not.

Use the required Keyword in C# to Enforce Property Initialisation

Last week we saw how much code we can get rid of when we use the [init keyword to create immutable objects]. The only downside we found was that we cannot enforce that all properties get a value. To solve this problem, we can use the required keyword of C# 11:

The required modifier indicates that the field or property it is applied to must be initialized by an object initializer. Any expression that initializes a new instance of the type must initialize all required members. – from learn.microsoft.com

The init Keyword for Immutable Properties in C

With C# 9 we got the new init keyword. You may have heard of it when it was introduced, but probably not used it much at the time. Then as with so many new things in the C# language, the new syntax did not offer new functionality but syntactic sugar to get the same results faster. Why should we care now? Because in combination with other newer features in C# that init keyword is a great help.

What was the init keyword again?

The init keyword defines an accessor method in a property or indexer. An init-only setter assigns a value to the property or the indexer element only during object construction. An init enforces immutability, so that once the object is initialized, it can't be changed. – from learn.microsoft.com

Little Git Tricks: Revert Changes in a File

If you want to revert a change in a file with Git, you can use this command:

git checkout -- ./path/to/file
The double-hyphen (--) tells Git to take what follows as its second argument (the path to the file). This makes it clear that you did not specify a branch.

While this works, it is not ideal. You might wonder what command to use or where the -- should go. It can be hard to remember and we often need to check the documentation to make sure we do it the right way. Is there a better way?

5 Things to Test With List Parameters

Whenever we have a method that accepts a list as a parameter, we should test these 5 cases to see if the method handles the input correctly:

  1. Null
  2. Empty
  3. One
  4. A few
  5. Many

Let us take a closer look at each of those inputs and what they can check for us. The list is not my invention, but so far, I was unable to attribute it correctly. If you know who the source was, please let me know.

How to Fix the Multiple Entry Points Error in .Net Applications

Before I start making changes, I usually run the template code to see if everything works so far. Even when it only has the template code, problems could happen. A few weeks ago, I skipped this step and after I made my changes, I got this error:

Error (active) CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.