locked
Scaffold Postgres 13 database for EF Core RRS feed

  • Question

  • User-1262787652 posted

    Looking for a method to create EF core entity classes from existing Postgres 13 database in Windows.

    Database has 300 tables.

    According to

    http://www.npgsql.org/efcore/index.html In Visual Studio 2019 command prompt

    dotnet ef dbcontext scaffold "Host=my_host;Database=my_db;Username=my_user;Password=my_pw" Npgsql.EntityFrameworkCore.PostgreSQL

    Command should do this but it throws error

    Could not execute because the specified command or file was not found.

    Possible reasons for this include:

    • You misspelled a built-in dotnet command.
    • You intended to execute a .NET program, but dotnet-ef does not exist.
    • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

    I verified that NpgSql.EntityFrameworkCore.PostgreSQL v5.0.1 package is installed from Nuget.

    How to create entity classes for EF Core in Postgres ?

    Monday, December 28, 2020 12:15 AM

All replies

  • User1312693872 posted

    Hi,kobruleht

    Could not execute because the specified command or file was not found.

    According to this error message, you can try running VS as an admin and adding

    Install-Package Microsoft.EntityFrameworkCore.Tools

    in Package Manager Console.

    create entity classes for EF Core in Postgres

    This a tutorial, you can check it:

    https://medium.com/@RobertKhou/getting-started-with-entity-framework-core-postgresql-c6fa09681624

    Best Regards,

    Jerry Cai

    Monday, December 28, 2020 8:38 AM
  • User-1262787652 posted

    Hi!

    I installed tools:

    Package Manager Console Host Version 5.8.0.6930
    Type 'get-help NuGet' to see all available NuGet commands.
    PM> Install-Package Microsoft.EntityFrameworkCore.Tools
    Restoring packages for I:\myapp\Store\Store.csproj...
    GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.tools/index.json
    OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.tools/index.json 473ms
    GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.tools/5.0.1/microsoft.entityframeworkcore.tools.5.0.1.nupkg
    OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.tools/5.0.1/microsoft.entityframeworkcore.tools.5.0.1.nupkg 21ms
    GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.design/index.json</div>  OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.design/index.json 136ms
    GET https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.design/5.0.1/microsoft.entityframeworkcore.design.5.0.1.nupkg
    OK https://api.nuget.org/v3-flatcontainer/microsoft.entityframeworkcore.design/5.0.1/microsoft.entityframeworkcore.design.5.0.1.nupkg 19ms
    Installing Microsoft.EntityFrameworkCore.Design 5.0.1.
    Installing Microsoft.EntityFrameworkCore.Tools 5.0.1.
    Installing NuGet package Microsoft.EntityFrameworkCore.Tools 5.0.1.
    Committing restore...
    Generating MSBuild file I:\myapp\Store\obj\Store.csproj.nuget.g.props.
    Writing assets file to disk. Path: I:\myapp\Store\obj\project.assets.json
    Restored I:\myapp\Store\Store.csproj (in 1,45 sec).
    Successfully uninstalled 'Microsoft.CSharp 4.5.0' from Store
    Successfully installed 'Humanizer.Core 2.8.26' to Store
    Successfully installed 'Microsoft.CSharp 4.7.0' to Store
    Successfully installed 'Microsoft.EntityFrameworkCore.Design 5.0.1' to Store
    Successfully installed 'Microsoft.EntityFrameworkCore.Tools 5.0.1' to Store
    Executing script file 'C:\Users\myuser\.nuget\packages\microsoft.entityframeworkcore.tools\5.0.1\tools\init.ps1'
    Executing nuget actions took 4,14 sec
    Time Elapsed: 00:00:06.2699254

    but dotnet ef still produces same errror

    I:\myapp>dotnet ef
    Could not execute because the specified command or file was not found.
    Possible reasons for this include:
      * You misspelled a built-in dotnet command.
      * You intended to execute a .NET program, but dotnet-ef does not exist.
      * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
    Monday, December 28, 2020 10:08 AM
  • User1312693872 posted

    Hi,konruleht

    Try this in cmd:

    dotnet tool install --global dotnet-ef --version 5.0.1

    Best Regards,

    Jerry Cai

    Tuesday, December 29, 2020 3:29 AM