To convert an ASP.NET Core Web API application that uses an SQL Server database to a PostgreSQL database, you can follow these steps. We’ll use the QuickApp ASP.Net Core web API project template as a concrete example for this migration :
- Install the required PostgreSQL NuGet packages:
- In your ASP.NET Core project, install the
Npgsql.EntityFrameworkCore.PostgreSQLpackage using the NuGet Package Manager or thedotnet add packagecommand. - This package provides the necessary PostgreSQL provider for Entity Framework Core.
- Update the database configuration:
- In your
appsettings.jsonfile, update the connection string to point to your PostgreSQL database instead of the SQL Server database. - The connection string for PostgreSQL might look something like this:
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=your_database_name;Username=your_username;Password=your_password"
}
- Update the DbContext configuration:
- In your Program.cs (or
Startup.cs) file, configure the DbContext to use the PostgreSQL provider for Entity Framework Core. - Replace the following line:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer(connectionString, b => b.MigrationsAssembly(migrationsAssembly));
...
});
with:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseNpgsql(connectionString, b => b.MigrationsAssembly(migrationsAssembly));
...
});
- Make a similar modification in the DesignTimeDbContextFactory.cs file. Replace the lines:
builder.UseSqlServer(configuration["ConnectionStrings:DefaultConnection"],
b => b.MigrationsAssembly(migrationsAssembly));
...
with:
builder.UseNpgsql(configuration["ConnectionStrings:DefaultConnection"],
b => b.MigrationsAssembly(migrationsAssembly));
...
- Migrate the database schema:
- If you have existing migrations for the SQL Server database, you’ll need to update them to work with PostgreSQL.
- You can do this by running the following commands in the Package Manager Console or the CLI:
# Remove the existing migrations dotnet ef migrations remove # Add a new migration for PostgreSQL dotnet ef migrations add InitialPostgreSQLMigration # Update the database to the new PostgreSQL schema dotnet ef database update
- Update your data models and queries:
- Review your data models and queries to ensure they are compatible with PostgreSQL.
- Test your application:
- Run your ASP.NET Core Web API application and ensure that it’s properly connecting to the PostgreSQL database and performing CRUD operations as expected.



3 Comments
Docs Medical Billing, LLC.
September 17, 2024 at 2:55 pmDocsMed provides comprehensive revenue cycle management services to medical practices across the US. Our expert team ensures efficient medical billing, reduced claim denials, and optimized financial performance. Serving over 50 medical specialties, we streamline workflows, improve profitability, and enhance cash flow for healthcare providers nationwide.
Visit Us: https://docsmedicalbilling.com/
xawomo50
October 1, 2025 at 7:55 amMigrating from SQL Server to PostgreSQL in an ASP.NET Core app is definitely doable, but you’ll need to update a few key parts of your project:
Entity Framework Provider – Replace Microsoft.EntityFrameworkCore.SqlServer with Npgsql.EntityFrameworkCore.PostgreSQL.
Connection Strings – Update your appsettings.json to use PostgreSQL connection format, e.g. Host=localhost;Database=mydb;Username=myuser;Password=mypass.
Data Types – Some SQL Server types don’t directly map to PostgreSQL (like uniqueidentifier, datetime, etc.), so you may need to adjust your models or use custom configurations.
Migrations – Recreate migrations for PostgreSQL to avoid incompatibility issues.
Testing – Run thorough integration tests since SQL functions and behaviors (like case sensitivity in text fields) differ.
For a step-by-step guide with practical examples on handling database migrations and setting up a robust web app environment, you can also check here:
https://www.theardor.com.au/web-development/
trustedbrands
November 17, 2025 at 11:52 amMigrating an ASP.NET Core Web App or Web API from SQL Server to PostgreSQL is more than a technical shift — it’s a strategic upgrade that boosts performance, flexibility, and long-term scalability. With PostgreSQL’s powerful indexing, richer JSON support, and open-source freedom, your application gains the ability to handle complex data scenarios with cleaner architecture.
Visit: https://eco-liv.com/