Latest Articles

Entity Framework Core
Is "N+1 Queries" still a performance issue in Entity Framework Core 3?
In a previous post we saw that EF 2.1 is highly susceptible to the N+1 queries problem. After the release of a new version of Entity Framework Core (EF) the first question coming to mind is: "Is it still a big issue in EF 3.1?" And if the answer is no, is there anything else we…
Pawel Gerr
Entity Framework Core
Entity Framework Core 3.0 - "Hidden" GROUP BY Capabilities (Part 2)
In the previous blog post we used a navigational property to work around the limitations of the extension method . The problem is, there is not always such a property we can use for grouping. Especially, when following domain driven design practices, a bidirectional navigation is…
Pawel Gerr
Entity Framework Core
Entity Framework Core 3.0 - "Hidden" GROUP BY Capabilities (Part 1)
With Entity Framework Core 3.0 (EF) the internal implementation of the LINQ query translation has been changed a lot. So, some queries that didn't work previously are working now and some that worked are not working anymore. :) The LINQ extension method is a special one…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Getting more Deadlock Information with named Transactions
Whether in an application in production or in integration tests on CI, the deadlocks are virtually unavoidable. The behavior of a deadlock depends on the database (MS SQL Server, MySQL, etc)  and the isolation level (like Snapshot Isolation). Some of the databases are blocking…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Beware of Lifetime Extension of TransactionScopes using C# 8.0
In the blog post Entity Framework Core: Use TransactionScope with Caution! we saw a few cases we have to be aware of when using . Here is another one that can lead to an exception when using the new C# 8.0 feature: . First, we look at a code snippet without C# 8.0 feature: Which…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Include Filters
The Entity Framework Core (EF) extension method provides us the ability to load additional data besides the entities we are querying for. For example: loading products along with their translations. In some use cases we want to load all translations for the requested products…
Pawel Gerr
ASP.NET
ASP.NET Core 3.0 - Custom JsonConverter for the new System.Text.Json
With the introduction of ASP.NET Core 3.0 the default JSON serializer has been changed from Newtonsoft.Json to System.Text.Json. For projects and libraries switching to the new JSON serializer this change means more performance and the opportunity to rewrite our . Serialization…
Pawel Gerr
.NET
C# 8 - Nullable Reference Types in .NET Standard < 2.1 and .NET 4.x
By switching the to and setting to in the csproj-file we are now benefiting from the introduced with the latest version of C#. By enabling this new feature all type members, input and output parameters are considered to be not-null. If some members or parameters, like can…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Making RowNumber (more) useful
In the blog post ROW_NUMBER Support we saw how to implement a custom function and in the previous post Improved Value Conversion Support we realized that inserting and selecting custom types is one thing but using them for filtering is something totally different. Let's take a…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Improved Value Conversion Support
Entity Framework Core (EF) 2.1 introduced a new feature called Value Conversion. Now, we are able to map custom .NET types to a type the database understands and vice versa. This long-awaited feature is especially popular among software engineers following the domain driven…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Custom Functions (using HasDbFunction)
In the previous post (Custom Functions - using IMethodCallTranslator) we looked at the more flexible approach that requires some boilerplate code. For the usage of a custom function in a project, especially if there are no plans to make the function public then the sacrifice of…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Custom Functions (using IMethodCallTranslator)
In the previous blog post (Entity Framework Core: ROW_NUMBER Support) we saw how to use the custom function with Entity Framework Core (EF). Now, we will look into the implementation. In the next and the last post of this series we will look ath the 2nd approach that uses the…
Pawel Gerr
Entity Framework Core
Entity Framework Core - ROW_NUMBER Support
There are some use cases that force me to use raw T-SQL instead of using LINQ. One of them is the need for ROW_NUMBER. But not anymore... One again, due to great work of Entity Framework (EF) team we are able to add more capabilities to EF quite easily. At the moment there are…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Contains Check via Temp Tables
Motivation One of the main queries in my projects is to select multiple database records having a collection of some kind of identifiers. Most of the time it works very well using the method . The query above is translated by the Entity Framework Core (EF Core) to clause: Most…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Isolation of Integration Tests
When working with Entity Framework Core (EF) a lot of code can be tested using the In-Memory database provider but sometimes you want (or have) to go to the real database. For example, you are using not just LINQ but custom SQL statements due to performance reasons or you want to…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Changing DB Migration Schema at Runtime
In the first part of this short blog post series we looked at how to change the database schema of a DbContext, now it is all about changing the schema of the EF Core Migrations at runtime. The samples are on Github: PawelGerr/EntityFrameworkCore-Demos Given is a  implementing…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Use TransactionScope with Caution!
One of the new features of Entity Framework Core 2.1 is the support of TransactionScopes. The usage of a  is very easy, just put a new instance in a , write the code inside the block and when you are finished then call to commit the transaction: But, before changing your code…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Changing Database Schema at Runtime
At the moment there is no built-in support for changing the database schema at runtime. Luckily, Entity Framework Core (EF) provides us with the right tools to implement it by ourselves. The demos are on GitHub: github:PawelGerr/EntityFrameworkCore-Demos Given are a database…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Inheritance - Table-per-Type (TPT) is not supported, is it? (Part 2 - Database First)
In the previous post we have created 2 Entity Framework Core (EF Core) models with a code first approach. One model was using the Table-per-Hierarchy (TPH) pattern and the other one Table-per-Type (TPT). In this post we want to approach a more common scenario we see in customer…
Pawel Gerr
Entity Framework Core
Entity Framework Core - Inheritance - Table-per-Type (TPT) is not supported, is it? (Part 1 - Code First)
With O/R mappers there are a few patterns how a class hierarchy can be mapped to a relational database. The most popular ones are the Table-Per-Hierarchy (TPH) and the Table-Per-Type (TPT) patterns. The Entity Framework Core 2.x (EF Core) officially supports the Table-per…
Pawel Gerr
Entity Framework Core
Entity Framework Core 2.1 Performance - Beware of N+1 Queries (Revisited)
In the previous post we have identified some Entity Framework (EF) LINQ queries that are affected by so called N+1 queries problem. In the meantime a new version (2.1-RC1) of Entity Framework has been released so we check the SQL statement generation yet another time. Samples…
Pawel Gerr
Entity Framework Core
Entity Framework Core Performance - Beware of N+1 Queries
After working with Entity Framework 6 (EF 6) for several years, a software developer can predict the SQL statements being generated by EF just by looking at the LINQ queries. With Entity Framework Core (EF Core) the SQL statement generation has changed - in some cases for the…
Pawel Gerr
.NET Core
(ASP).NET Core in production - Changing log level temporarily - 2nd approach
In the previous blog post I talked about how to change the log level at runtime by coupling the (or rather the ) with the . However, the solution has one drawback: you need to change the file  for that. In this post we will be able to change the log level without changing the…
Pawel Gerr
.NET Core
.NET Core in production - Changing log level temporarily
When running the application in production then the log level is set somewhere between and . The question is what to do if you or your customer experiences some undesired behavior and the logs with present log level aren't enough to pinpoint the issue. The first solution that…
Pawel Gerr
ASP.NET
ASP.NET Core - Update to Autofac 4.6.1 recommended - more than a bugfix release
If you are using Autofac in your ASP.NET Core application then I recommend to update Autofac to version 4.6.1. This bugfix release brought a change how child scope handle additional registrations so that some errors like just disappear. With additional registrations I mean the…
Pawel Gerr
ASP.NET
ASP.NET Core in production - Graceful shutdown and reacting to aborted requests
In the previous post "ASP.NET Core in production: Take back control of your web app" I mentioned that getting hold if the dependency injection (DI) is just one step of many to improve the architecture of your web applications. Today well will look into 2 other aspects that are…
Pawel Gerr
ASP.NET
ASP.NET Core in production - Take back control of your web app
With ASP.NET Core the setup of a new MVC or a Web API project is essentially a 2-liner. The standard setup you can find in most tutorials is ideal for demos, workshops or simple web apps but is insufficient for complex applications. The standard setup looks as follows: The rest…
Pawel Gerr
ASP.NET
ASP.NET Core - Beware - Singleton may not be singleton
If you register a type as a singleton then you expect just 1 instance of this type in your whole application. What you may not know is that ASP.NET Core is creating 2 instances of during building of the that may lead to 2 instance of your "singleton". This is the case if you…
Pawel Gerr
ASP.NET Core
ASP.NET Core Web API Performance - Throughput for Upload and Download
After working with the new ASP.NET Core server and the for a while in a number of projects I run into some performance issues. Actually, it was a throughput issue. It took me some time to figure out whether it is the server or the client responsible for the problems. And the…
Pawel Gerr
Entity Framework Core
Entity Framework Core Migrations - Assembly Version Mismatch
If you have switched your .NET Core project from to (MSBuild) and updated the nuget packages then you may run into an issue when executing some of the -commands. I got the following error after executing : The problem is that some of my (3rd party) dependencies are using…
Pawel Gerr
.NET
Strongly-typed Configuration for .NET Core - with full Dependency Injection support
Configuration is one of the most prominent cornerstones in software systems, and especially in distributed systems. And it has been a point for discussions in .NET for quite some time. In one of our projects we have built a solution that lets different applications in different…
Pawel Gerr
ASP.NET
ASP.NET Core with IIS - Setup Issues
If you are planing to run an ASP.NET Core application with IIS then this blog post might be worth a glance. These are a few issues I run into ... 1. Targets in .xproj-file If the project started with RC1 or earlier version of .NET Core then check for correct targets. Open the…
Pawel Gerr
ASP.NET
(ASP).NET Core Dependecy Injection - Disposing
After several years of using the same Dependency Injection (DI) framework like Autofac you may have a good understanding how your components, implementing the interface IDisposable, are going to be disposed. With the nuget package Microsoft.Extensions.DependencyInjection the new…
Pawel Gerr
.NET
.NET Abstractions - It's not just about testing!
With the introduction of .NET Core we got a framework that works not just on Windows, but on Linux and macOS as well. One of the best parts of .NET Core is that the APIs stayed almost the same compared to the old .NET, meaning developers can use their .NET skills to build cross…
Pawel Gerr
Entity Framework
Entity Framework - Prevent redundant JOINs - watch your LINQ !
Fetching one record from a collection using navigational properties in Entity Framework may lead to unnecessary JOINs. To show the problem we need two tables Products and Prices. The query shown below is fetching products along with their first price. Looks simple. Lets look at…
Pawel Gerr
Angular
Mimicking $interpolate - An Angular 2 interpolation service
In an Angular 1 application we have been creating for one of our customers we used the $interpolate service to build a simple templating engine. The user was able to create snippets with placeholders within the web application to use these message fragments to compose an email to…
Pawel Gerr
Entity Framework
Entity Framework - High performance querying trick using SqlBulkCopy and temp tables
Implementing database access with Entity Framework is pretty convenient, but sometimes the query performance can be very poor. Especially using navigational properties to load collections leads to significantly longer execution times and more I/O. To see the impact of the loading…
Pawel Gerr
.NET
.NET Core - Lowering the log level of 3rd party components
With the new .NET Core framework and libraries we have got an interface called Microsoft.Extensions.Logging.ILogger to be used for writing log messages. Various 3rd party and built-in components make very good use of it. To see how much is being logged just create a simple Web…
Pawel Gerr
AngularJS
AngularJS - Dynamic Directives
In this post, we will look into an approach for exchanging the definition of an AngularJS directive, i.e. the template, controller, compile/link functions etc., after the application has been bootstrapped whereby carrying out a full reload is not an option. Assume that you have…
Pawel Gerr