Home > front end >  How to make database connectivity in ASP.NET core with PostgreSQL?
How to make database connectivity in ASP.NET core with PostgreSQL?

Time:12-27

How to make database connection in ASP.NET core with postgres SQL ?

CodePudding user response:

use the Npgsql EF Core provider, add a dependency on Npgsql.EntityFrameworkCore.PostgreSQL. You can follow the instructions in the general EF Core Getting Started docs. enter image description here

ConfigureServices in startup.cs: Once you successfully added the Nuget package then you have to update following code on your project ConfigureServices under startup.cs

        services.AddDbContext<YourDatabaseContextClassName>(options =>
        options.UseNpgsql(Configuration.GetConnectionString("YourDatabaseContextStringNameFromAppsettings")));

Note: If you need any example for entityframework and Postgre SQL implementation you can have look here

For further assistance you can have look on official document here. Hope it would guide you accordingly.

  • Related