Posts

Modern Mapping with EF Core

Image
Introduction In EF Core (as in most O/RMs) we can map and store multiple things: Objects that hold a single value, like int , string , bool , float , Guid , DateTime , TimeSpan , Uri , etc. These are (somewhat wrongly) called primitive types  and are always included inside some container, like the following Objects that hold multiple single values and which have an identity, for example, Customer , Product , Order . These are called entity types  and they must have an identity that makes them unique amongst all the other objects of the same type Objects that are structured to hold multiple values, but have no identity, such as Address , Coordinate . These are called value types  and are merely a collection of (possibly related) properties We can also have collections of the previous things There's more to it, of course, for example, it is even possible to represent  inheritance of entities , of which I talked about before , In this post I am going to cover so...

ASP.NET Core Pitfalls - Content Type Mismatch

Introduction To get the new year started, another post on my ASP.NET Core Pitfalls series! This time, it's related to APIs, and how the [Consumes] attribute is interpreted. The Problem The Content-Typ e header and optional charset parameter are part of the web standard and used to tell the server handler what type of content the client will send. The charset part is optional, and the default is " ascii "; for example, if we wish to set it as UTF-8 , we should sent: Content-Type: application/json;charset=utf-8 Now, charset is optional, and does not really change what the content type is, just the character set of the text of the payload. In ASP.NET Core, it can be used to route the request to different endpoints: for example, two action methods for the same action can consume different content types. There is an attribute,  [Consumes] , which can be used in ASP.NET Core MVC to restrict the content types that are accepted by a given action method. [HttpGet("Get...

2025 in Retrospective

So, 2025 has come to an end, and we are already in 2026!  To me, 2025 was a very important year, for some reasons: I stopped using my old blog,  https://weblogs.asp.net/ricardoperes . This is essentially because Microsoft/Neudesic stopped supporting it. Most contents are still there, but there are some that are unavailable, and I don't think there's much we can do about it. Some of these contents were migrated to my new blog (here where you are reading this) Got back to posting regularly here, in some weeks, I even published more than one post Started my PhD ! I intend to write more about it soon Kept on being a Microsoft MVP ! In 2025 I published ~50 posts, of which: 1 was on GitHub Actions (my first one on this topic) 2 were on ASP.NET Core pitfalls (more to come) 2 were on EF Core pitfalls (more to come) 2 were on ASP.NET Core extension points (more to come) 2 were on OpenTelemetry and Metrics 3 were on multitenancy (more to come) 4 were non-technical, announcements or com...

.NET 10 Validation

Note: this is an update to my original post . Introduction I wrote about  entity validation  in the past, the reason I'm coming back to it is that there are some changes in .NET 10, related to validation. Let's cover the original validation API and then explain what has changed. .NET Validation Validation is implemented in the System.ComponentModel.DataAnnotations namespace. I'll describe it first and then move to the small changes in .NET 10. .NET has featured a way to validate classes and their properties for a long time, the API is called  Data Annotations Validation , and it integrates nicely with ASP.NET Core MVC and other frameworks (not Entity Framework Core, as  I've talked recently , nor ASP.NET Core Minimal APIs ). It is essentially, but not just, based on a set of attributes, one interface, and a class that performs validations on a target class and its properties, from the validation attributes it contain. The base class for attribute validation is ca...

Nullable and Required Types

Introduction Since the introduction of nullable reference types in C#, and also with the required keyword, I sometimes see some confusion, which I'm going to address here. This is kind of back to basics, but, yet, here we are! ;-) Reference Types A reference type in C#/.NET is a type that: Are instantiated on the heap Are passed by reference (pointer) Can be null Are declared with the class keyword (can also be record , in latest versions) Meaning, for example, that we can have this (string is a reference type): string str = null; str = "Hello, referece types!"; Value Types On the other hand, value types : Are instantiated on the stack Are passed by value (copied on every method call) Cannot be null Always have a value Are declared using the struct , enum , or record struct keywords Implicitly inherit from System.ValueType Value types are numbers, booleans, bytes, characters, enumerations, and some basic structures such as DateTime , Guid , or T...

Multitenancy Techniques for the UI in ASP.NET Core

Updated view expander code, thanks Thomas Ardal ! Introduction I've been writing some posts on multitenancy with ASP.NET Core. So far we have: Tenant identification Data filtering (for EF Core) UI customisation (this article) Business logic  This time I'm going to talk about the User Interface (UI) and give some suggestions for: Loading contents inside of a view conditionally per tenant Loading different views for different tenants Using code for making tenant-dependent choices We shall be referencing the same ITenantIdProvider abstraction shown before. All the views I'll be talking about are, of course, Razor views , which can be views in a MVC app or Razor Pages . Loading Different Views per Tenant Views are used to render HTML contents in a MVC project. The actual service that is responsible for locating the views files is IViewLocationExpander . We will implement our own version that sticks another path to the list of paths used to search for views ...