All Projects → jasonsturges → postgresql-dotnet-core

jasonsturges / postgresql-dotnet-core

Licence: other
ASP.NET Core 3.1 Web Application using PostgreSQL with Entity Framework

Programming Languages

C#
18002 projects
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to postgresql-dotnet-core

mysql-dotnet-core
ASP.NET Core 5.0 Web Application using MySQL with Entity Framework
Stars: ✭ 95 (+21.79%)
Mutual labels:  coreclr, entity-framework, aspnet-core
sqlite-dotnet-core
.NET Core 2.1 Console Application using SQLite with Entity Framework and Dependency Injection
Stars: ✭ 17 (-78.21%)
Mutual labels:  coreclr, entity-framework
Run Aspnetcore Cqrs
Real world Enterprise CRM application example of ASP.NET Core + Angular web application. Implemented CQRS Design Pattern for ASP.NET Core + Angular reference application, demonstrating a layered application architecture with DDD best practices. Download 100+ page eBook PDF from here ->
Stars: ✭ 152 (+94.87%)
Mutual labels:  entity-framework, aspnet-core
Dntidentity
A highly customized sample of the ASP.NET Core Identity
Stars: ✭ 145 (+85.9%)
Mutual labels:  entity-framework, aspnet-core
Peachpie
PeachPie - the PHP compiler and runtime for .NET and .NET Core
Stars: ✭ 1,945 (+2393.59%)
Mutual labels:  coreclr, aspnet-core
react-redux-aspnet-core-webapi
No description or website provided.
Stars: ✭ 34 (-56.41%)
Mutual labels:  entity-framework
Udemy-MyEvernote-Sample-Project
ASP.NET MVC Yazılımcıların Yükselişi eğitimim için hazırladığım örnek proje.
Stars: ✭ 66 (-15.38%)
Mutual labels:  entity-framework
EFCore.Sqlite.NodaTime
Adds support for NodaTime types when using SQLite with Entity Framework Core.
Stars: ✭ 21 (-73.08%)
Mutual labels:  entity-framework
ASP.NET-Core-2-MVC-CRUD-datatables-jQuery-Plugin
Asp.Net Example implementation of datatables.net using Asp.Net Core 2 Mvc CRUD datatables jQuery Plugin
Stars: ✭ 25 (-67.95%)
Mutual labels:  entity-framework
AppsTracker
Windows Application for tracking computer usage. C# + WPF + MVVM
Stars: ✭ 27 (-65.38%)
Mutual labels:  entity-framework
AzureADAuthRazorUiServiceApiCertificate
Azure AD flows using ASP.NET Core and Microsoft.Identity
Stars: ✭ 41 (-47.44%)
Mutual labels:  aspnet-core
AspNetCoreMvcSharedLocalization
ASP.NET Core MVC shared localization
Stars: ✭ 31 (-60.26%)
Mutual labels:  aspnet-core
Giraffe.TokenRouter
Alternative routing API for Giraffe web applications which is aimed at maximum performance.
Stars: ✭ 21 (-73.08%)
Mutual labels:  aspnet-core
OrdersManagementSystem
Project demonstrates usage of Prism composition library, Material design library, SQL Server, Entity Framework in WPF application
Stars: ✭ 29 (-62.82%)
Mutual labels:  entity-framework
Elasticsearch-Autocomplete-API-Sample
Building Autocomplete API with Completion Suggester in ASP.NET Core sample project
Stars: ✭ 20 (-74.36%)
Mutual labels:  aspnet-core
Snai.CMS
内容管理后台
Stars: ✭ 25 (-67.95%)
Mutual labels:  aspnet-core
ChatService
ChatService (SignalR).
Stars: ✭ 26 (-66.67%)
Mutual labels:  aspnet-core
OpenSleigh
OpenSleigh is a Saga management library for .NET Core.
Stars: ✭ 198 (+153.85%)
Mutual labels:  entity-framework
BlipDrop
ASP.NET MVC case study solution for PluralSight Guides. Demonstrates how to use populate dropdown lists in Razor views.
Stars: ✭ 40 (-48.72%)
Mutual labels:  entity-framework
AspNetCore.DataProtection.Aws
AWS S3 & KMS integration for ASP.NET Core data protection
Stars: ✭ 62 (-20.51%)
Mutual labels:  aspnet-core

PostgreSQL ASP.NET Core 3.1

Convert an ASP.NET Core Web Application project to use PostgreSQL with Entity Framework.

This enables development of ASP.NET Core projects using VS Code on macOS or linux targets.

This project uses .NET Core 3.1 target framework, ASP.NET Core Web Application project scaffold from Visual Studio 2019 (version 16.4.5).

vscode

Project setup has already been completed in this repository - assure environment setup; then, jump to running the solution.

Environment Setup

This project requires PostgreSQL - installation instructions are provided below.

If using Visual Studio Code, you will need to generate ASP.NET Core developer certificates by issuing the following commands from a terminal:

dotnet dev-certs https --clean
dotnet dev-certs https

For command line database ef commands, you will need to install Entity Framework Core tools .NET CLI:

dotnet tool install --global dotnet-ef

Project Setup

Below, instructions are referenced to use PostgreSQL in a ASP.NET Core project.

Install NuGet packages

Install the Npgsql.EntityFrameworkCore.PostgreSQL NuGet package in the ASP.NET web application.

To do this, you can use the dotnet command line by executing:

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

Or, edit the project's .csproj file and add the following line in the PackageReference item group:

<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.2" />

Update appsettings.json

Configure connection string in project's appsettings.json, replacing the username, password, and dbname appropriately:

"ConnectionStrings": {
    "DefaultConnection": "User ID=username;Password=password;Server=localhost;Port=5432;Database=dbname;Integrated Security=true;Pooling=true;"
},

Modify Startup.cs

Inside Startup.cs ConfigureServices() method, replace the UseSqlServer option with PostgresSQL:

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddDbContext<ApplicationDbContext>(options =>
        options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));

Running the solution

Before the solution can be executed, be sure to run entity framework migrations.

Migration Issues with DbContext

Initial migrations may fail, due to ASP.NET Core template come with a pre-generation migration for SQL Server.

When trying to run the migration, you might see errors such as:

System.NullReferenceException: Object reference not set to an instance of an object. System.InvalidOperationException: No mapping to a relational type can be found for property 'Microsoft.AspNetCore.Identity.IdentityUser.TwoFactorEnabled' with the CLR type 'bool'.

Delete the entire Migrations folder, and regenerate new inital migrations.

Generate a new migration using Visual Studio Package Manager Console (from menu: Tools -> NuGet Package Manager -> Package Manager Console):

PM> Add-Migration

Or, from the command line via DotNet CLI:

$ dotnet ef migrations add Initial

Run Entity Framework Migrations

Execute the migration using either Visual Studio Package Manager Console (from menu: Tools -> NuGet Package Manager -> Package Manager Console):

PM> Update-Database

Or, from the command line via DotNet CLI, execute the following command inside the project directory, where the .csproj file is located:

$ dotnet ef database update

After running the migration, the database is created and web application is ready to be run.

Setting up a PostgresSQL server on Mac

Here are instructions to setup a PostgreSQL server on Mac using Homebrew.

Installing PostgreSQL on Mac

Use brew to install PostgreSQL, then launch the service:

$ brew install postgresql
$ brew services start postgresql

Create a user

Create a user using the createuser command from a terminal. Using the -P argument, you will be prompted to setup a password.

$ createuser username -P

Create a database

Create your database using the createdb command from a terminal.

$ createdb dbname

At this time, run the solution's Entity Framework migrations (see above for instructions).

Verifying database

Launch PostgreSQL interactive terminal and connect to the database.

$ psql dbname

From the PostgreSQL interface terminal, List tables using the \dt command:

dbname=# \dt
                   List of relations
 Schema |         Name          | Type  |    Owner     
--------+-----------------------+-------+--------------
 public | AspNetRoleClaims      | table | username
 public | AspNetRoles           | table | username
 public | AspNetUserClaims      | table | username
 public | AspNetUserLogins      | table | username
 public | AspNetUserRoles       | table | username
 public | AspNetUserTokens      | table | username
 public | AspNetUsers           | table | username
 public | __EFMigrationsHistory | table | username
(8 rows)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].