Dotnet Core API Crud With Mysql and EF Core

Dotnet Core API Crud With Mysql and EF Core

In this tutorial, we are going to make dotnet core web api application and perform all the CRUD (create, read, update and delete). I have tried to keep it simple and avoided any complexities like repository pattern.

💻Source code

Tech and tools used

  • Dotnet 10
  • MySql 8+ (in docker container. Click here, if you want to create a MySql container in docker)
  • Entity Framework Core (ORM)
  • .NET CLI and VS Code (alternate Visual Studio 2025)

Creating a project

Execute these commands in a sequence.

[Read More]

Dotnet Core API Crud With Mysql and Dapper

Dotnet Core API Crud With Mysql and Dapper

In this tutorial, we are going to make dotnet core web api application and perform all the CRUD (create, read, update and delete). I have tried to keep it simple and avoided any complexities like repository pattern.

💻Source code

Tech and tools used

  • Dotnet 10
  • MySql 8+ (in docker container. Click here, if you want to create a MySql container in docker)
  • Dapper (ORM)
  • .NET CLI and VS Code (alternate Visual Studio 2025)

Create database

Let’s start with creating a database and a table. You need to execute this script.

[Read More]

LeftJoin and RightJoin in Ef Core 10

LeftJoin and RightJoin in  Ef Core 10

Previously there was no simple solution for left or right join. We had to use DefaultIfEmpty or GroupJoin and SelectMany.

With DefaultIfEmpty():

var customerOrders = await (
    from c in ctx.Customers
    join o in ctx.Orders on c.CustomerId equals o.CustomerId into orders
    from o in orders.DefaultIfEmpty()
    select new {
        c.CustomerId,
        c.CustomerName,
        OrderId = o == null ? 0 : o.OrderId
    }
).ToListAsync();

I have used the way described above in most of my career. It was really hard to remember that syntax and I always struggled with that.

[Read More]

Cartesian Explosion and Split Query in Entity Framework Core

Cartesian Explosion and Split Query in Entity Framework Core

In this tutorial, we will understand what cartesian explosion is and how to solve that problem. Let’s look at this query:

var people = await ctx.People
   .Include(p => p.Emails)
   .Include(p => p.Addresses)
   .ToListAsync();

It translates to:

 SELECT "p"."Id", "p"."FirstName", "p"."LastName", "e"."Id", "e"."PersonEmail", "e"."PersonId", "a"."Id", "a"."PersonAddress", "a"."PersonId"
      FROM "People" AS "p"
      LEFT JOIN "Emails" AS "e" ON "p"."Id" = "e"."PersonId"
      LEFT JOIN "Addresses" AS "a" ON "p"."Id" = "a"."PersonId"
      ORDER BY "p"."Id", "e"."Id"
  • Person joins with Email and Address. Both joins are at the same level.
  • A person can have multiple emails and adressess.

Let’s say a person with id = 1 have 10 emails and 10 addresses. The query returns 1x10x10 = 100 rows for 1 person. It is just for one person, how much they can be for 100 people. This problem is known as cartesian explosion

[Read More]

Lazy Loading and N+1 Query Problem in Entity framework Core

Lazy Loading and N+1 Query Problem in Entity framework Core

💻Source code

Lazy loading

You load related entities on demand rather loading at once. This approach is usually useful when you want to load related entities on a certain condition (otherwise always use eager loading).

To enable lazy loading, you need to install this package: Microsoft.EntityFrameworkCore.Proxies

And do following changes in Program.cs

builder.Services.AddDbContext<AppDbContext>(o=>o.UseLazyLoadingProxies()
.UseSqlite("Data Source = mydb.db"));

Look at the example below:

app.MapGet("/", async (AppDbContext context) => {
    foreach (var genre in await context.Genres.ToListAsync()) 
    {
        foreach (var book in genre.Books)
        {
            Console.WriteLine($"===> genre: {genre.Name}, Book: {book.Title}, Price : {book.Author}");
        }
    }
    return Results.Ok("Ok");
});

We are not loading books with genres at once. Rather we are loading books for each genres. Let’s take a look at logs of console.

[Read More]

Content Negotiation in Dotnet Core Webapi

Content Negotiation in Dotnet Core Webapi

As defined in rfc2616 - “Content nagotiation is the process of selecting the best representation for a given response when there are multiple representations available.”

Clients passes the header Accept with values like application/json,application/xml etc and tells this format is acceptable. Then server gives the response according to that.

In simpler terms, if your API supports xml, json and csv media type, then let clients decide which kind of media type they need as a response.

[Read More]

Containerizing Dotnet App With PostgreSql Using Docker Compose

Containerizing Dotnet App With PostgreSql Using Docker Compose

In this tutorial, we are going to containerize the .NET Web API application with docker and postgres. I am assuming you are familiar with docker. At least, you should have some understandings of how docker works. However, I have covered all the steps needed to create a docker container for your application, but I am not going to cover the theoretical concepts of docker.

📢Last updated : 21-Nov-2025

[Read More]

Containerizing Dotnet App With Sql Server Using Docker Compose

Containerizing Dotnet App With Sql Server Using Docker Compose

In this tutorial, we are going to containerize the .NET Web API application with docker. I am assuming you are familiar with docker. At least, you should have some understandings of how docker works. However, I have covered all the steps needed to create a docker container for your application, but I am not going to cover the theoretical concepts of docker.

Last updated on:

  • 20-November-2025

🔨Tools needed

  • Visual Studio Code (Free)
  • .Net 10.0 SDK (Free)
  • Docker desktop (Free)

🧑‍💻Tech used

  • .Net 10.0 Web APIs (controller APIs)
  • Ms SQL Server 2025 (within a container)
  • Docker compose

🍵Note: I am using windows 11 operating system. However, I also have tested it in the Linux mint xia and it is working fine.

[Read More]

Azure Key Vault With Dotnet

Azure Key Vault With Dotnet

First of all, let’s see what are we going to achieve? Let’s say we have an dotnet 9 api application.

Its appsettings.json looks like:

 "Color": "Color from appsettings",
 "Person": {
   "Name": "Name from appsettings"
 }

Let’s try to retrieve these values:

app.MapGet("/", (IConfiguration config) =>
{
    string color = config.GetSection("Color").Value ?? "No color";
    string name = config.GetSection("Person:Name").Value ?? "No name";
    return Results.Ok(new
    {
        color,
        name,
        message = "Hello there..."
    });
});

If you visit this endpoint, you will see this output:

[Read More]

Azure App Configuration With Dotnet(C#)

Azure App Configuration With Dotnet(C#)
  • Azure App Configuration is a fully managed service, which provides you a way to store the configurations in a centralized store. You can store configurations of multiple apps in a single place.
  • It is really helpful for cloud native application (eg. Microservices), which runs on multiple virtual machines and use multiple external services.
  • It allows us to store Key-value pairs, manage feature flags, and organize configurations using labels and namespaces.
  • The main benefit is, it supports dynamic refreshing. Which means, you can change config values without restarting the app.
  • You can also add reference of azure key vault secret here.

Let’s see these things in action.

[Read More]