Tell, don’t Ask

The most languages i develop in these days are OOP (Object Oriented Programming) languages and i try to use the SOLID-principles as much as possible. The first principle in SOLID is the Single Responsibility Principle (SRP), which states that a class should have only one reason to change. In other words, it should only have […]

Custom MVC validation attribute

Finding my self in a new-old situation i needed to create a custom validation attribute. To create an custom validation attribute we inherit from the abstract class “ValidationAttribute” in System.ComponentModel.DataAnnotations. This allows for server side validation by invoking the method “IsValid”. I decided to implement an “MoreThan” attribute which checks that the one value in my […]

Create self signed certificate

Today i started a project what utilized IdentityServer and for that i needed a signed certificate. This post might not be the best explained, but more like a reminder for my self. param ( [Parameter(Mandatory=$true)][string]$subject = “My SelfSigned Certificate”, [string]$outputPath = (Get-Item -Path “.\” -Verbose).FullName, [Parameter(Mandatory=$true)][string]$password #[string]$password = $( Read-Host “Input password, please” ) ) […]

Map private fields in Entity framework core

In DDD you always want to control what is being put into your domain object. That can be done with public getters and private setters. But when it comes to collections (e.g. System.Collections.Generic.List<T>) it becomes more complicated, due to the fact the the domain object exposes an object of type List<T> which can be modified.

Testing DBContext migrations

Today i was creating EntityFrameworkCore DBContexts and it’s a time consuming work to delete the databases, add migrations and then update the database to see what the migration scripts would generate. I created a simple powershell-script that i ran when needed. Write-Host “Deleting the migrations folder…” Remove-Item “Migrations” -Force -Recurse Write-Host “Dropping database ASPD..” sqlcmd […]

State pattern in C#

The state design patterns is a behavioral pattern that implements a state machine in an object-oriented way. It allows an object/class to alter its behavior when its internal state changes. Lets say that we have a competition application that allows clients to register score, but only when the competition is open. A non state pattern design […]

Kill Linux processes

We have an old messy thirdparty application at work that uses Oracle. Sometimes the application tends to lock the Oracle system and use a LOT of threads, leaving the system pretty much unresponsive. To be able to kill all 1000+ Oracle-plus processes i created a small script that kills all processes.

Shrink transactionlogs

To shrink the MS-SQL transactionlogs for emergency storage needs we can use the following syntax. USE MYDB; GO — Truncate the log by changing the database recovery model to SIMPLE. ALTER DATABASE MYDB SET RECOVERY SIMPLE; GO — Shrink the truncated log file to 1 MB. DBCC SHRINKFILE (MYDB_Log, 1); GO — Reset the database […]

Tablecopy with T-SQL

Today i found myself in a situation where i needed to copy some data from one table on a MS-SQL server to another. I found the following T-SQL syntax to be very helpfull. UPDATE DST SET DST.Title = SRC.Title, DST.ContractNumber = SRC.ContractNumber, DST.ContractDescription = SRC.ContractDescription FROM Contracts AS DST INNER JOIN [SERVERNAME].[DBNAME].DBO.Contracts AS SRC ON […]