Skip to content

Book List from Bhrugen Patel's ASP.NET Core 2.1 Udemy course using Postgresql.

Notifications You must be signed in to change notification settings

jwzabrenski/book-list-postgres

Repository files navigation

BookList RazorPostgres

Razor Pages BookList project from Bhrugen Patel's .Net Core 2.1 Udemy course using PostgreSQL instead of MS SQL Server.

To use PostgreSQL as your db, first install the EntityFrameworkCore NuGet package:

$ dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL --version 2.1.0

Then, update the ApplicationDbContext.cs file to include the below method:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
             => optionsBuilder.UseNpgsql("Host=server;Database=dbName;Username=username;Password=password");

In Startup.cs, add the following to the ConfigureServices method, above services.AddMvc()

            services.AddEntityFrameworkNpgsql()
            .AddDbContext<ApplicationDbContext>(
                options => options
                .UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));

Finally, your connection string in the appsettings.json file should be:

"ConnectionStrings": {
    "DefaultConnection" : "Host=servername;Port=portnumber;Username=username;Password=password;Database=DBname;"
  }

About

Book List from Bhrugen Patel's ASP.NET Core 2.1 Udemy course using Postgresql.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published