Skip to main content


EF Core - The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

Athough EF Core is a developer friendly Object-Relational Mapper (ORM), working with it isn't without its challenges. One error that we encountered during a pair programming session was: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value In this blog post, we will delve into the causes of this error and explore ways to resolve it. "Constructing a database in the 18th century" - Generated by AI Understanding the error This error typically occurs when there is an attempt to convert a datetime2 value in SQL Server to a datetime value, and the value falls outside the valid range for the datetime data type. datetime : This data type in SQL Server has a range from January 1, 1753, to December 31, 9999, with an accuracy of 3.33 milliseconds. datetime2 : This newer data type, introduced in SQL Server 2008, has a much broader range from January 1, 0001, to December 31, 9999, with an accuracy of 100 nanoseconds.
Recent posts

Automating MassTransit Consumer Registration

When working with MassTransit, registering consumers can become cumbersome if you have many of them. Luckily, MassTransit provides a way to register all your consumers automatically using AddConsumers . This post will guide you through the process of setting up and using AddConsumers to simplify your consumer registration. What is MassTransit? MassTransit is an open-source distributed application framework for .NET, which simplifies the creation and management of message-based systems. It supports various messaging platforms like RabbitMQ, Azure Service Bus, and Amazon SQS. Setting Up MassTransit Before diving into consumer registration, let’s quickly set up a MassTransit project. Step 1: Install MassTransit Packages First, install the necessary MassTransit packages via NuGet. You can use the following command on your favorite command line: dotnet add package MassTransit.RabbitMQ Step 2: Configure MassTransit In your Program.cs or wherever you configure your service

Don’t talk about non-functional requirements, talk about quality attributes

When discussing software development, terms shape our perception and priorities. One such discussion revolves around the terminology used for requirements that go beyond direct functionalities. Traditionally, when talking about architectural needs, I used to call them non-functional requirements (NFRs). However, I switched recently to a  more fitting term—quality attributes—as it may better emphasize their importance and value.    Generated by AI Let me explain why this more than just a semantic change but a strategic enhancement… What are non-functional requirements? Before I explain my reasoning, let me shortly define what non-functional requirements are: Non-functional requirements (NFRs), also known as quality attributes, refer to criteria that judge the operation of a system rather than specific behaviors or functions. These requirements define the overall qualities and characteristics that the system must possess, ensuring it meets user needs and performs efficiently an

Debug your .NET 8 code more efficiently

.NET 8 introduces a lot of debugging improvements. If you take a look for example at the HttpContext , you see that you get a much better debug summary than in .NET 7: .NET 7: .NET 8: But that is not a feature I want to bring under your attention. After recently updating my Visual Studio version, I noticed the following announcement among the list of new Visual Studio features: That is great news! This means that you can debug your .NET 8 applications without a big performance impact on the rest of your code. The only thing we need to do is to disable the Just My Code option in Visual Studio: If we now try to debug a referenced release binary, only the relevant parts are decompiled without impacting the other code: More information Debugging Enhancements in .NET 8 - .NET Blog (

EF Core - Error CS1503 Argument 2: cannot convert from 'string' to 'System.FormattableString'

I was pair programming with a team member when she got the following compiler error: Error CS1503 Argument 2: cannot convert from 'string' to 'System.FormattableString' The error appeared after trying to compile the following code: The reason becomes apparent when we look at the signature of the SqlQuery method: As you can see the method expects a FormattableString not a string . Why is this? By using a FormattableString EF Core can protect us from SQL injection attacks. When we use this query with parameters(through string interpolation), the supplied parameters values are wrapped in a DbParameter . To get rid of the compiler error, we can do 2 things: 1. We explicitly create  a FormattableString from a regular string: 2. We use string interpolation and add a ‘$’ sign in front of the query string: More information SQL Queries - EF Core | Microsoft Learn RelationalDatabaseFacadeExtensions.SqlQuery<TResult> Method (Microsoft.EntityF

Git–Dubious ownership

Today I had a strange Git error message I never got before. When I tried to execute any action on a local Git repo, it fails with the following error: git status fatal: detected dubious ownership in repository at 'C:/projects/examplerepo' 'C:/projects/examplerepo' is owned by: 'S-1-5-32-544' but the current user is: 'S-1-5-21-1645522239-329068152-682003330-18686' To add an exception for this directory, call: git config --global --add C:/projects/examplerepo Image generated by AI What does this error mean and how can we fix it? Let’s find out! This error means that the current user is not the owner of the git repository folder. Before git executes an operation it will check this and if that is not the case it will return the error above. The reason why this check exists is because of security reasons. Git tries to avoid that another user can place files in our git repo folder. You can check the owner of a directory by executing

EF Core - Query splitting

In EF Core when fetching multiple entities in one request it can result in a cartesian product as the same data is loaded multiple times which negatively impacts performance. An example is when I try to load a list of Customers with their ordered products: The resulting query causes a cartesian product as the customer data is duplicated for every ordered product in the result set. EF Core will generate a warning in this case as it detects that the query will load multiple collections. I talked before about the AsSplitQuery method to solve this. It allows Entity Framework to split each related entity into a query on each table: However you can also enable query splitting globally in EF Core and use it as the default. Therefore update your DbContext configuration: More information EF Core–AsSplitQuery() ( Single vs. Split Queries - EF Core | Microsoft Learn