How to Get the Remote Host IP Address in ASP.NET Core Web API
In this article, we will learn what is a remote host IP address and explore different ways to extract it in ASP.NET Core Web API. Let's start....
How to Store JSON in an Entity Field With EF Core
In this article, we are going to talk about how to store data in the JSON entity field using Entity Framework Core. But before we start, we...
Extending LINQ to Objects With MoreLINQ Library
In this article, we'll explore the capabilities of the MoreLINQ library, which enables us to improve the already robust LINQ functionality.Β Let's...
Fast Inserts With Entity Framework (EF Core)
In this article, we will review multiple ways of performing fast inserts of bulk data into a database using the Entity Framework (EF for short). Entity Framework "classic" was introduced in 2008, was superseded nearly a decade later by EF Core, and continues to add...
How to Run an Async Method Synchronously in .NET
In this article, we will learn how to run an async method synchronously in .NET. Let's start. Different Ways We Can Run Asynchronous...
Easy Sorting, Filtering and Pagination in .NET With Sieve Package
Most applications that are developed nowadays usually involve interacting with non-trivial amounts of data, so we need to provide functionality for sorting and filtering in our applications. Moreover, speed and load times are increasingly important, so we don't want...
How to Return XML From ASP.NET Core Web API
ASP.NET Core is a powerful and flexible platform for building web applications. It supports multiple data formats, including JSON and XML, and provides many tools for serialization and deserialization. In this article, we will focus on how to return XML from ASP.NET...
Static Methods vs. Non-Static Methods in C#
In this article, we are going to look at the difference between static and non-static methods in C#. In truth, there are many .NET languages...
Short Circuit Evaluation of IF Statements with Await in C#
In this article, we are going to look at what exactly short circuit evaluation is in C# and how asynchronous calls are affecting it. [sc name="github" url="https://github.com/CodeMazeBlog/CodeMazeGuides/tree/main/async-csharp/ShortCircuitEvaluationWithAsyncAwait"...
How to Serialize Exceptions as JSON in .NET
In this article, we will learn how to serialize exceptions as JSON in .NET. Good exception handling is one of the key aspects of a successful enterprise application. And when we talk about an API, it's important that we provide relevant failure details to consumer...
C# Dictionary to JSON: How to Serialize Any Key Type
Resource-Based Authorization in ASP.NET Core
When authorizing requests in ASP.NET Core Web API projects, it's not enough to know the endpoint and the user; we also need to be aware of the specific resource the user is trying to access. In this article, we will learn how to tackle these situations using...
C# JSON Property Order: System.Text.Json and Newtonsoft
To control property order in JSON output we set it explicitly: [JsonPropertyOrder] in System.Text.Json, and [JsonProperty(Order = β¦)] in Newtonsoft.Json. Converters and contract resolvers exist for the cases those two attributes cannot reach, such as sorting a whole...
Aggregate Design in .NET: Aggregate Roots and Invariants
An aggregate groups domain entities that change together, and the aggregate root is its main entity. The root is the only way into the aggregate, and it enforces the invariants, the business rules that must hold at all times. We will get to know the main design...
Split a String in C#: Overloads and StringSplitOptions
String.Split() cuts a string into an array of substrings at every occurrence of a separator we name. "a,b,c".Split(',') returns ["a", "b", "c"]. The separator can be one character, one string, or an array of either, and every form accepts an optional...
Upcasting and Downcasting in C#
Upcasting and downcasting are important concepts in C# programming that allow us to convert an object of one type to another type. These concepts are essential to work with polymorphism and object-oriented programming. In this article, we will explore how upcasting...
How to Validate an Email Address in C# With or Without Regex
To validate an email address in C#, we can parse it with MailAddress.TryCreate(), check it with the EmailAddressAttribute, match it against a regular expression, or use FluentValidation's EmailAddress() rule. Each one lets different inputs through, and none of them...
How to Round Down a Number to the Nearest Integer in C#
To round a number down to the nearest integer in C#, we call Math.Floor() and cast the result to int: (int)Math.Floor(-1.25) gives -2. A plain cast gives -1 instead. Negative numbers are where most of the usual candidates go wrong. So we test the methods that would...
LINQ Join in C#: How to Do an Inner Join
An inner join in LINQ pairs each element of one sequence with every element of a second sequence that has the same key, and leaves out the elements that have no match. In C#, we write it with the join clause or the Join() method. We'll join two collections in both...
Handling CommandTimeout With Dapper in .NET
In this article, we are going to learn how to handle CommandTimeout with Dapper in .NET. So, letβs start. About Dapper Dapper is a...
C# Empty Array: Declare, Create and Initialize
An empty array in C# is Array.Empty<T>(), or [], which the compiler turns into the same thing. Both hand back one shared zero-length array instead of allocating a new one. The older spellings still work. new string[0], new string[] { } and string[] myArray = {...










