{"id":27391043,"url":"https://github.com/default-writer/dotnetcore20","last_synced_at":"2025-09-05T21:37:11.289Z","repository":{"id":135937633,"uuid":"113514090","full_name":"default-writer/dotnetcore20","owner":"default-writer","description":null,"archived":false,"fork":false,"pushed_at":"2017-12-08T02:21:59.000Z","size":5349,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-01T12:39:56.563Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/default-writer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-12-08T00:52:58.000Z","updated_at":"2017-12-17T09:57:58.000Z","dependencies_parsed_at":"2023-06-04T04:00:18.978Z","dependency_job_id":null,"html_url":"https://github.com/default-writer/dotnetcore20","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/default-writer/dotnetcore20","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/default-writer%2Fdotnetcore20","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/default-writer%2Fdotnetcore20/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/default-writer%2Fdotnetcore20/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/default-writer%2Fdotnetcore20/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/default-writer","download_url":"https://codeload.github.com/default-writer/dotnetcore20/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/default-writer%2Fdotnetcore20/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273826405,"owners_count":25175232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-13T20:11:27.909Z","updated_at":"2025-09-05T21:37:11.263Z","avatar_url":"https://github.com/default-writer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotnetcore20\n\n# Getting Started with EF Core on ASP.NET Core with an Existing Database (PostgreSQL)\n\n\u003e [!IMPORTANT]  \n\u003e The [.NET Core SDK](https://www.microsoft.com/net/download/core) no longer supports `project.json` or Visual Studio 2015. Everyone doing .NET Core development is encouraged to [migrate from project.json to csproj](https://docs.microsoft.com/dotnet/articles/core/migration/) and [Visual Studio 2017](https://www.visualstudio.com/downloads/).\n\nIn this walkthrough, you will build an ASP.NET Core MVC application that performs basic data access using Entity Framework. You will use reverse engineering to create an Entity Framework model based on an existing database.\n\n\u003e [!TIP]  \n\u003e You can view this article's [sample](https://github.com/hack2root/dotnetcore20/tree/master/dotnetcoremvc) on GitHub.\n\n## Prerequisites\n\nThe following prerequisites are needed to complete this walkthrough:\n\n* [Visual Studio 2017 15.3](https://www.visualstudio.com/downloads/) with these workloads:\n  * **ASP.NET and web development** (under **Web \u0026 Cloud**)\n  * **.NET Core cross-platform development** (under **Other Toolsets**)\n* [.NET Core 2.0 SDK](https://www.microsoft.com/net/download/core).\n* [PostrgeSQL 10.1](https://www.postgresql.org/)\n* [PostgreSQL Northwind database install scripts](#northwind-database)\n* [Npgsql](http://www.npgsql.org/doc/ddex.html)\n* [Npgsql Visual Studio extension (VSIX)](https://marketplace.visualstudio.com/items?itemName=RojanskyS.NpgsqlPostgreSQLIntegration)\n### Northwind database\n\nThis tutorial uses a **Northwind** database on your PostgreSQL instance as the existing database.\n\n\u003e [!TIP]  \n\u003e If you have already created the **Northwind** database as part of another tutorial, you can skip these steps.\n* Install PostgreSQL Northwind database\n  * Open solution folder dbnpgsql\n  * Set PostgreSQL system environment variables PGUSER, PGPASSWORD\n  * Run install.cmd as administrator\n* Open Visual Studio\n* **Tools -\u003e Connect to Database...**\n* Select **Postgre SQL Database** and click **Continue**\n* Enter **localhost** as the **Server Name**\n* Enter **northwind** as the **Database Name** and click **OK**\n* Enter **northwind_user** as the *User Name*\n* Enter **thewindisblowing** as the *Password*\n* The Northwind database is now displayed under **Data Connections** in **Server Explorer**\n\n[!code-sql[Main](dbnpgsql/northwind.sql)]\n## Create a new project\n\n* Open Visual Studio 2017\n* **File -\u003e New -\u003e Project...**\n* From the left menu select **Installed -\u003e Templates -\u003e Visual C# -\u003e Web**\n* Select the **ASP.NET Core Web Application (.NET Core)** project template\n* Enter **EFGetStarted.AspNetCore.ExistingDb** as the name and click **OK**\n* Wait for the **New ASP.NET Core Web Application** dialog to appear\n* Under **ASP.NET Core Templates 2.0** select the **Web Application (Model-View-Controller)**\n* Ensure that **Authentication** is set to **No Authentication**\n* Click **OK**\n\n## Install Entity Framework\n\nTo use EF Core, install the package for the database provider(s) you want to target. This walkthrough uses PostgreSQL Server.\n\n* **Tools \u003e NuGet Package Manager \u003e Package Manager Console**\n\n* Run `Install-Package Microsoft.EntityFrameworkCore.SqlServer`\n\nWe will be using some Entity Framework Tools to create a model from the database. So we will install the tools package as well:\n\n* Run `Install-Package Microsoft.EntityFrameworkCore.Tools`\n\nWe will be using some ASP.NET Core Scaffolding tools to create controllers and views later on. So we will install this design package as well:\n\n* Run `Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design`\n\n## Fix .NET Core 2.0 project issues\n* [Project file](/dotnetcoremvc/dotnetcoremvc.csproj)\n\n## Reverse engineer your model\n\nNow it's time to create the EF model based on your existing database.\n\n*Before you start, make shure you added some sections to *.cspoj file:\n* [Add autogenerate binding redirects](https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-entity-framework-core-2-0)\n  * Set AutoGenerateBindingRedirects flag to true in PropertyGroup\n* [Add Microsoft.EntityFrameworkCore and dependencies](https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db#blogging-database)\n  * Install-Package Npgsql.EntityFrameworkCore.PostgreSQL\n  * Install-Package Microsoft.EntityFrameworkCore\n  * Install-Package Microsoft.EntityFrameworkCore.Relational\n  * Install-Package Microsoft.EntityFrameworkCore.SqlServer\n  * Install-Package Microsoft.EntityFrameworkCore.Tools\n\n* **Tools –\u003e NuGet Package Manager –\u003e Package Manager Console**\n* Run the following command to create a model from the existing database:\n\n``` powershell\nScaffold-DbContext \"Database=northwind;Username=northwind_user;Password=thewindisblowing;Host=localhost;Persist Security Info=True\" Npgsql.EntityFrameworkCore.PostgreSQL -OutputDir Models -Verbose\n```\n\nIf you receive an error stating `The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet`, then close and reopen Visual Studio.\n\n\u003e [!TIP]  \n\u003e You can specify which tables you want to generate entities for by adding the `-Tables` argument to the command above. E.g. `-Tables Blog,Post`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefault-writer%2Fdotnetcore20","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefault-writer%2Fdotnetcore20","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefault-writer%2Fdotnetcore20/lists"}