This application is a simple C-sharp application built using the Entity framework and Neon database. It returns a list of authors and books written by them. This project uses the Entity Framework to interact with the Neon database and generate/run migrations.
To build this project from scratch, check out the guide in Neon's documentation.
You will need the following:
- A Neon account and a project
- A recent version of the .Net SDK installed on your local machine
- Run the following command to clone the project repository:
git clone https://github.com/neondatabase/guide-neon-entityframework.git
- Navigate to the project directory and run the following command to install the project dependencies:
cd guide-neon-entityframework
dotnet restore
dotnet tool install --global dotnet-ef
-
Create a
.env
file in the project root directory.Fetch the connection string from your Neon project, which is in the following format:
postgres://username:password@hostname/dbname?sslmode=require
Identify the components of the connection string and add them to the
.env
file by combining them as shown below:DATABASE_URL="Host=hostname;Port=5432;Database=dbname;Username=username;Password=password;SSLMode=Require"
-
Run the database migrations and seed the database with sample data:
dotnet ef database update
- Start the development server:
dotnet run
- Open your web browser and visit
http://localhost:5000
to view the list of authors and books.