Skip to main content

Inventory and Orders API for .NET C# and MySQL

ASP.NET Core and MySQL code that can't oversell the last unit, repeat a change or overrun its database connections.

  • .NET SDK
  • C#
  • ASP.NET Core
  • EF Core
  • MySql.EntityFrameworkCore

Screenshots

Screenshot 1 of 11: Title card: Inventory and Orders API, .NET C# source code, with its stack chips and a code window showing two orders for the last unit: one answered 201 Created, the other 409 Conflict.

Title card: Inventory and Orders API, .NET C# source code, with its stack chips and a code window showing two orders for the last unit: one answered 201 Created, the other 409 Conflict.

One-off price

  • ₹999+ GST at checkout
  • $19
  • Download it from your library as soon as your payment is confirmed.
  • Every later release of this project is included, at no extra cost.
Latest release
1.0.0 · Nov 6, 2026

Overview

The complete source code of an inventory and orders API in ASP.NET Core, EF Core and MySQL: categories, products, stock movements and orders, with 20 endpoints. Two buyers can't get the last unit, a retry can't repeat a change, and a burst of requests can't overrun the database connections. It runs on your own computer in six steps.

Most inventory samples work until two people buy the last unit at the same moment, a client retries after a lost reply, or a burst of traffic reaches the database. Inventory and Orders API for .NET C# and MySQL is the complete code for those moments, with results from real runs against MySQL 9.7.

What the API does

  • Categories and products. Search, filter, sort and page products, archive and restore them, and list the ones at or below their reorder level.
  • Stock. Record deliveries and corrections, with the full history of every change to each product.
  • Orders. Place an order, then fulfil it or cancel it. Cancelling puts the stock back.
  • 20 endpoints and 2 health checks. A .http file has a request for every endpoint, and Scalar adds interactive documentation in Development.

Built for the moments that break a demo

  • Two buyers, one last unit. One statement locks the row, checks the quantity and takes the stock. Of two orders sent at the same moment, one got 201 Created and the other 409 Conflict.
  • A retry can't repeat a change. Orders and stock changes take an Idempotency-Key. The same order sent twice came back as the same order, and the stock was taken once.
  • A burst can't end the process. With MySql.Data's default pool, 150 requests at once to a freshly started API ended the whole process in 17 of 26 runs. This API lets only as many requests run at once as the connection pool allows, and the same burst was clean in 8 of 8 runs. 600 orders sent at once were all placed in 5.5 seconds, with the stock exactly right.
  • Edits can't overwrite each other. A change based on an old version of a product gets a 409, and an order can only be fulfilled or cancelled once.
  • Clear answers when MySQL is down. Clients get a 503 with Retry-After and no stack trace, and the API carries on by itself when MySQL returns.

A careful MySQL connection

  • Encrypted. The setup uses SslMode=Required, the README shows how to move to VerifyFull, and outside Development the app warns at startup if it isn't checking the server.
  • Least privilege. One account for the API, which can only read and change rows, and another for migrations.
  • Time limits on the server. By default a statement waits 5 seconds at most for a row lock, and a SELECT runs for 30 seconds at most. They sit on the server because MySql.Data's async calls don't stop at CommandTimeout.
  • Retries that work. Oracle's provider treats no MySQL error as temporary unless it's listed. This code lists them, and starts each retry on a clean connection.
  • Migrations as their own step. Five EF Core migrations create the five tables, and the app never migrates itself.

Code you can build on

  • Clear structure. Minimal APIs with one folder per feature, in a solution with separate API and data projects.
  • Strict builds. Warnings are errors, the recommended analyzers are on, and every package version lives in one file.
  • Consistent errors and safe logs. Every error uses the problem details format, logs are JSON outside Development, and the password never reaches them.
  • Secrets out of the code. .env for the local MySQL, user-secrets in development and an environment variable everywhere else.

What it doesn't include

It's the API code and nothing else, so you know what to add:

  • No UI. It answers JSON.
  • No sign-in. Put your own authentication or gateway in front of it.
  • No test project. The results above come from running it against MySQL, not from automated tests in the archive.
  • No hosting. How you deploy it is up to you, and the README lists what the code expects from where it runs.

Run it in six steps

  1. Create the local passwords.
  2. Start MySQL with Docker Compose.
  3. Give the API and the migrations their own accounts.
  4. Create the tables.
  5. Store the connection string.
  6. Start the API, and open its documentation.

The README has every command, for macOS and Linux and for PowerShell. How to Set Up and Run the Inventory and Orders API (opens in a new tab) shows each step with what it should print. It was tested from a clean copy on macOS, in zsh and PowerShell 7.

Learn how it was built

The free 5-part tutorial series How to Connect a .NET C# Web API to a MySQL Database (opens in a new tab) explains the connection, the migrations, reading and writing data, transactions and locks, and the production checklist behind this code.

Free tutorial series

How to Connect a .NET C# Web API to a MySQL Database

Prefer to learn by building it? This free, step-by-step guide on our blog shows how the project is made.

Read the series (opens in a new tab)

What you get

Everything in the archive, at a glance.

  • Version 1.0.0 of the complete source code: a .NET 10 solution with an API project and a data project
  • 20 endpoints for categories, products, stock and orders, plus liveness and readiness health checks
  • Five EF Core migrations that create the five MySQL tables
  • Orders that can't oversell the last unit, and Idempotency-Key support on orders and stock changes
  • A limit on requests running at once, sized from the connection pool, plus a per-client limit and a request size limit
  • A retry strategy and server-side time limits built for Oracle's MySQL provider
  • A compose.yaml that runs MySQL 9.7 for development, and an .env.example
  • A .http file with a request for every endpoint, and Scalar API documentation in Development
  • A README with setup commands for macOS, Linux and PowerShell, every setting, and what to do before production

Built with

The exact runtimes and versions it was built and tested against.

  • .NET SDK10.0.403
  • C#14
  • ASP.NET Core10.0.14
  • EF Core10.0.14
  • MySql.EntityFrameworkCore10.0.12
  • MySql.Data26.10.0
  • Scalar.AspNetCore2.19.0
  • dotnet-ef10.0.14
  • MySQL9.7.4
  • Docker Compose5.6.1

What is in the archive

The file tree you get once you unzip it.

inventory-orders-api-dotnet-csharp-mysql/

  • src/
  • .editorconfig
  • .env.example
  • .gitattributes
  • .gitignore
  • compose.yaml
  • Directory.Build.props
  • Directory.Packages.props
  • dotnet-tools.json
  • global.json
  • README.md

What it needs from you

The accounts and services it expects to find, so nothing is a surprise.

  • The .NET 10 SDK
  • Docker Compose, through Docker Desktop or another install, for the local MySQL
  • A MySQL server for production: it was tested against MySQL 9.7 LTS in Docker, not against a managed service
  • Your own sign-in or gateway before it faces anything you don't trust, because the API is open
  • A host that restarts the process if it ends: a stalled TLS handshake makes MySql.Data throw an exception no code can catch
  • Optional: VS Code or Visual Studio

Releases

Every version so far, newest first.

  1. 1.0.0Latest

    First release of the complete source code.

    • An inventory and orders API in ASP.NET Core and MySQL, with 20 endpoints for categories, products, stock and orders.
    • Two buyers can't get the last unit, and a repeated request with the same Idempotency-Key can't repeat a change.
    • A burst of requests waits its turn instead of overrunning the database connections.
    • Least-privilege MySQL accounts, an encrypted connection, EF Core migrations and a README that takes you from the archive to a running API.

Source Code Licence

What you may do with it

What you may and may not do with the source code you buy.

Read the full licence
  1. What this licence covers

This licence governs every file included in a product you buy from Dewiride Store: source code, configuration, database scripts, sample data, documentation and any other file in the download. It takes effect when your payment is confirmed and applies to every release of that product that reaches your library. Files that reach your library through an annual updates membership are governed in exactly the same way.

It forms part of the Terms of Sale and Use. Where a product page states different or additional licence terms for that product, those terms prevail for that product. The membership page may likewise state different or additional licence terms for the files a membership carries, and those terms then prevail for those files.

  1. The licence we grant you

We grant you a perpetual, worldwide, non-exclusive, non-transferable licence to use, reproduce, adapt, translate and modify the files, and to include the result in your own work, on the conditions set out below.

Perpetual means it does not expire. Worldwide means it is not limited to any country. Non-exclusive means we license the same product to other customers. Non-transferable means you cannot pass it on to someone else.

The licence is granted to you — either you personally, or the organisation you identified when buying. Everyone working within that organisation may use the files for that organisation’s projects. Nobody outside it may.

  1. What you may do
  • Use and change the files in your own projects, commercial or otherwise, with no limit on the number of projects.
  • Build a product or a service on them and charge your own customers for it.
  • Deploy the result for a client, as part of work you are doing for that client.
  • Distribute the result in compiled, deployed or otherwise non-source form.
  • Keep as many back-up copies as you reasonably need.
  • Study, observe and test how the code works, and obtain the information you need to make it work with your own software.

The last two are yours by law under sections 52(1)(aa) to (ac) of the Indian Copyright Act, 1957, and nothing in this licence is intended to take them away.

  1. What you may not do
  • Resell, sublicense, redistribute or publish the files themselves, in whole or in substantial part, in source form.
  • Include them in a template, starter kit, course, tutorial repository or component library that you sell or give away, where the code is the thing being supplied.
  • Share your account, your download links or your invoices with anyone outside your organisation.
  • Publish the files in a public repository, or in any other place where they can be obtained without buying them.
  • Remove or obscure the copyright and attribution notices in the source files.
  • Use the files to build something whose main purpose is to compete with Dewiride Store as a supplier of the same code.

The distinction that matters is simple: you may sell what you build with the code; you may not sell the code.

  1. Third-party components

Our products depend on open-source libraries, frameworks and services that we did not write. Those remain under their own licences, which we do not and cannot change. Where a product includes or requires such a component, its licence is named in the product’s documentation, and complying with it is your responsibility.

  1. Releases

Every release of a product you own is covered by this same licence and appears in your library at no extra cost. A release you have already downloaded remains licensed to you even if we later stop publishing the product. A release that reached your library through an annual updates membership is licensed to you on these same terms, and stays licensed after the period that carried it has ended.

  1. Ownership

We keep ownership of the files and of the copyright in them. You own whatever you create with them: your changes, your additions and the product you build are yours.

  1. If this licence ends

This licence ends if you materially breach it and do not put the breach right within thirty days of us asking you to in writing. It also ends if your payment is reversed or refunded, because the purchase it depends on no longer stands. Where a membership period is refunded or reversed, the licence ends for the releases that period carried and for nothing else: anything you bought separately, or that another period carried, is unaffected.

If it ends, you must stop using the files and delete the copies you hold. Work you had already delivered to a client before that point may continue in use, so that ending this licence never breaks something your own customer relies on.

  1. No warranty beyond the description

The warranties and limits in section 19 and section 20 of the Terms of Sale and Use apply to this licence as well.

  1. Governing law

This licence is governed by the law of India, and section 24 of the Terms of Sale and Use applies to any dispute about it. If a translation and the English version differ in meaning, the English version governs.