EF Core Notes

1. Reverse Engineer DB (Comand Line Method)

  • This is the command line version.

    1. Microsoft doc is here.

    2. Right mouse click on the project and launch the Open In Terminal console window.

    3. You may need to first adjust NuGet package sources so that the downloads will succeed.

      EFCore NuGet Package Manager
    4. Install EF Core Tools. Doc is here.

      dotnet tool install --global dotnet-ef
    5. Confirm installation

      dotnet ef
      Example output
                           _/\__
                     ---==/    \\
               ___  ___   |.    \|\
              | __|| __|  |  )   \\\
              | _| | _|   \_/ |  //|\\
              |___||_|       /   \\\/\\
      
      Entity Framework Core .NET Command-line Tools 9.0.2
    6. Install EF packages:

      Example
      dotnet add package Microsoft.EntityFrameworkCore
      1. Microsoft.EntityFrameworkCore

      2. Microsoft.EntityFrameworkCore.Design

      3. Microsoft.EntityFrameworkCore.SqlServer (for MSSQLServer DB)

      4. Microsoft.EntityFrameworkCore.Sqlite (for SQLite DB)

      5. Microsoft.EntityFrameworkCore.OleDb (for Excel)

      6. Oracle.EntityFrameworkCore (for Oracle DB)

    7. Run one of the following to Scaffold a DB:

      Example for SQL Server
      dotnet ef DBContext scaffold  "Data Source=p-ubuntu-norco\sqlexpress,1285;database=repository;TrustServerCertificate=True;User Id=<UserID>;Password=<Password>;" Microsoft.EntityFrameworkCore.SqlServer --context-dir DBContext --context <context name>Context --output-dir DBModels --use-database-names --no-onconfiguring --no-build --force (1)
      Example for SQL Lite
      dotnet ef DBContext scaffold  "Data Source=C:\Users\mattosd\Downloads\Portal_DB.db" Microsoft.EntityFrameworkCore.Sqlite --context-dir DBContext --context <context name>Context --output-dir DBModels --use-database-names --no-onconfiguring --no-build --force (1)
      1 Replace <context name> with a name for the DBContext e.g., database name
    8. To use a trusted connection:

      Remove
      User Id=<UserID>;Password=<Password>;
      Replace with
      Trusted_Connection=True;
    9. To specify individual Table(s), add:

      --table <table name> --table <table name 2>

2. Reverse Engineer DB (Gui Method)

2.1. Download

You’ll need to shutdown all instances of Visual Studio before installing the following:
  • Download from here and then run the EF_Core_Power_Tools_v2.6.xxx.vsix installer.

  • Download from here and then run the EF_Core_Power_Pack_v2.6.xxx.vsix installer.

  • Download from here and then run the Oracle.VsDevTools.17.0.vsix installer.

  • Download from here and then run the MermaidEditor.vsix installer.

2.2. Launch the Tool

  1. Right mouse click on the project folder EF Core Power Tools  Reverse Engineer.

    EF-Core-Rev-Engineer

2.2.1. Create DB Connection

  1. Click the add Add button

    EF-Core-Rev-Engineer-Add-DB

  2. Enter the connection properties

    EF-Core-Rev-Engineer-Add-DB-Params

2.2.2. Select DB Objects

  1. Connect to the DB

    EF-Core-Rev-Engineer-Select-DB

  2. Select DB Objects

    EF-Core-Rev-Engineer-Select-DB-Objects

  3. Generate the DB Model

    EF-Core-Rev-Engineer-Gen-Model

  4. View New Folders and DB Objects

    EF-Core-Rev-Engineer-Folders