.NET + PostgreSQL

ASP.NET Core services in C# with PostgreSQL through Npgsql and EF Core, a common choice for cloud-native .NET outside the SQL Server default.

  • .NET.NET
  • C#C#
  • PostgreSQLPostgreSQL
Learning curve
Moderate
Status
Actively developed
Reviewed
November 2026
Best for
  • .NET teams moving to Linux containers and Kubernetes
  • Organisations avoiding SQL Server licensing or Azure lock-in
  • Line-of-business APIs and SaaS backends with strict typing requirements
  • Services that need PostgreSQL features such as jsonb, PostGIS or full-text search
Not ideal for
  • Quick prototype by a non-.NET team

Overview

ASP.NET Core on .NET serves HTTP through Kestrel, with C# business logic and EF Core (or Dapper) talking to PostgreSQL through Npgsql, the open-source ADO.NET driver and EF Core provider. Compared with the SQL Server default, teams get a licence-free database that every cloud offers as a managed service, plus PostgreSQL types such as jsonb, arrays and ranges mapped into C#. It suits .NET shops building containerised services on Linux or on clouds other than Azure.

What's inside

C# and ASP.NET Core are well documented; the learning is in DI lifetimes, async patterns, EF Core's change tracker and query translation, and PostgreSQL-specific behaviour around casing, time zones and pooling.

  • .NET

    .NET

    Backend

    Handles requests, business logic and APIs

    Learning: Moderate

    Status: Active

  • PostgreSQL

    PostgreSQL

    Database

    Stores and queries the data

    Learning: Moderate

    Status: Active

  • C#

    C#

    Language

    The language the code is written in

    Learning: Moderate

    Status: Active

How it works

Kestrel runs the ASP.NET Core middleware pipeline and routes requests to Minimal API endpoints or controllers; a scoped DbContext translates LINQ into PostgreSQL SQL through Npgsql's pooled connections and maps rows back into C# types.

  1. 1.

    Infrastructure to backend

    An ingress or reverse proxy forwards the request to Kestrel, and the ASP.NET Core middleware pipeline runs authentication, authorization, rate limiting and routing.

  2. 2.

    Backend to backend

    Model binding and validation turn the request into C# records; the endpoint calls services resolved from the DI container, including a scoped DbContext.

  3. 3.

    Backend to database

    EF Core translates LINQ (or Dapper sends hand-written SQL) into parameterised PostgreSQL queries, executed asynchronously over Npgsql's built-in connection pool.

  4. 4.

    Database to backend

    Npgsql maps PostgreSQL types (timestamptz, jsonb, arrays, uuid) to .NET types, and the endpoint serialises results with System.Text.Json.

Strengths and drawbacks

Strengths

  • High throughput with low ceremony

    Kestrel and async/await deliver strong request throughput, and Minimal APIs let small services stay compact without giving up DI, typed configuration and middleware.

  • Mature, actively maintained provider

    Npgsql's EF Core provider tracks EF Core releases and maps PostgreSQL arrays, ranges, enums, full-text search, PostGIS (via NetTopologySuite) and NodaTime types into LINQ.

  • Strong tooling and typing

    C# nullable reference types, Roslyn analyzers, Rider or Visual Studio debugging and profiling, and EF Core migrations make large refactors safe.

  • Predictable release cadence

    .NET ships a major release every November, with even-numbered versions as LTS releases supported for three years, which makes upgrade planning straightforward.

  • Cloud-neutral database

    PostgreSQL is available as a managed service on every major cloud and on-premises, so the same app moves between providers without changing database engines.

Drawbacks

  • SQL server assumptions in the ecosystem

    Many Microsoft samples, older libraries and job schedulers assume SQL Server first; PostgreSQL support often comes from community packages, and T-SQL habits such as case-insensitive comparisons do not carry over.

  • Identifier casing in raw SQL

    EF Core creates PascalCase table and column names, which PostgreSQL treats as quoted identifiers, so raw SQL and BI tools need double quotes everywhere unless you adopt a snake_case naming convention early.

  • Strict DateTime handling

    Npgsql maps timestamptz to UTC DateTime and rejects writing DateTime values with Kind=Local or Unspecified there; migrating older code that stores local times surfaces many runtime errors.

  • EF core performance traps

    Change tracking on read-only queries, multiple Include calls causing cartesian explosion, and client-side evaluation surprises need AsNoTracking, AsSplitQuery and log review.

  • Pooling with external poolers

    Npgsql pools connections per process; adding PgBouncer in transaction mode requires adjusting settings such as connection reset and prepared statements, which teams often miss.

Scores

Editorial ratings out of 10, comparable across every stack in the guide. They are judgement, not benchmarks. How we score

Speed of building
7.8 out of 10, catalog average 7.7

How quickly a team ships features

Ease of learning
7.0 out of 10, catalog average 7.2

Higher means easier to pick up

Scalability
9.0 out of 10, catalog average 7.6

How far it grows before a redesign

Performance
9.0 out of 10, catalog average 7.5

Speed of the running application

Maintainability
8.8 out of 10, catalog average 7.2

How well the codebase ages

Ecosystem
8.2 out of 10, catalog average 8.2

Libraries, hosting, docs and hiring

Flexibility
7.6 out of 10, catalog average 7.4

How many kinds of product it suits

How it scales

Stateless ASP.NET Core containers scale horizontally on any orchestrator; Npgsql pool sizes times instances against PostgreSQL connection limits, and write throughput on the primary, are the usual ceilings.

Starting outMVP and first users
A single ASP.NET Core container or App Service instance connected to a managed PostgreSQL server, with EF Core migrations applied at deploy.
GrowingReal traffic, a few engineers
Several containers on Kubernetes, ECS or Container Apps, output and distributed caching, health checks, and PgBouncer or a provider pooler in front of PostgreSQL.
LargeHeavy traffic or data
Separate read and write DbContexts with Npgsql multi-host connection strings targeting replicas, background work in hosted services or a queue, and compiled queries on hot paths.
EnterpriseMany teams and regions
Service-per-domain architecture with its own PostgreSQL databases, messaging via RabbitMQ or Kafka, and distributed PostgreSQL options such as Citus where a single primary is not enough.

Where it fits

Common projects, from best fit to worst.

  • Line-of-business API on Kubernetes

    Strongly typed domain logic, EF Core migrations and Linux containers on a managed PostgreSQL service without database licence costs.

    Great fit

  • Migrating off SQL server

    Keeps the C# codebase while swapping providers; stored procedures, T-SQL functions and collation-dependent queries need rewriting and testing.

    Good fit

  • Geospatial or document-style data

    PostGIS through NetTopologySuite and jsonb columns are queryable from LINQ, covering cases that would otherwise need a separate store.

    Good fit

  • Quick prototype by a non-.NET team

    Project structure, DI, EF Core and C# tooling take time to learn; Rails, Django or Laravel get a newcomer team to a demo faster.

    Poor fit

Alternatives

Similar stacks, and when you would choose them instead.

Sources

Reviewed on November 19, 2026 against the documentation below. Found something out of date? Suggest a correction. Read our methodology.

Stacks that share technologies with .NET + PostgreSQL.