Connect an Entity Framework application to Neon
Set up a Neon project in seconds and connect from an Entity Framework application
This guide describes how to create a Neon project and connect to it from an Entity Framework Core application. The example demonstrates how to set up a basic ASP.NET Core Web API project with Entity Framework Core using Npgsql as the database provider.
note
The same configuration steps can be used for any .NET application using Entity Framework Core, including ASP.NET Core MVC, Blazor, or console applications.
To connect to Neon from an Entity Framework application:
- Create a Neon Project
- Create a .NET project and add dependencies
- Configure Entity Framework
- Run the application
Create a Neon project
If you do not have one already, create a Neon project.
- Navigate to the Projects page in the Neon Console.
- Click New Project.
- Specify your project settings and click Create Project.
Create a .NET project and add dependencies
-
Create a new ASP.NET Core Web API project and change to the newly created directory:
-
Delete the files
WeatherForecast.cs
andControllers/WeatherForecastController.cs
as we won't be using them: -
Install required packages
IMPORTANT
Ensure you install package versions that match your .NET version. You can verify your .NET version at any time by running
dotnet --version
.
Configure Entity Framework
-
Create a model class in
Models/Todo.cs
: -
Create a database context in
Data/ApplicationDbContext.cs
: -
Update
appsettings.json
/appsettings.Development.json
:Add the connection string:
-
Create a Todo controller in
Controllers/TodoController.cs
: -
Update
Program.cs
: -
Create and apply the initial migration:
Run the application
-
Start the application:
-
Test the connection by navigating to
http://localhost:5001/swagger
in your browser. You can use the Swagger UI to create and retrieve Todo items.
Source code
You can find the source code for the application described in this guide on GitHub.
Resources
Need help?
Join our Discord Server to ask questions or see what others are doing with Neon. Users on paid plans can open a support ticket from the console. For more details, see Getting Support.