Skip to content

Database Scaffolding

JainalGandhi edited this page May 19, 2020 · 3 revisions

To scaffold the database

1. Run the following commands in the ./WediumAPI directory

  dotnet ef dbcontext scaffold "<Connection String>" Microsoft.EntityFrameworkCore.SqlServer -o Models -f

Replace <Connection String> with the connection string of the database. If running on mac then special characters (such as $, &, %, #) need to be escaped by adding a \ before them.

2. Go to Models/WediumContext.cs and remove the connection string from the file. The beginning of the file should look like the following

  namespace WediumAPI.Models
  {
      public partial class WediumContext : DbContext
      {
          public WediumContext()
          {
          }

          public WediumContext(DbContextOptions<WediumContext> options)
              : base(options)
          {
          }

          public virtual DbSet<Comment> Comment { get; set; }

          ...