dotnet tool install --global dotnet-ef
dotnet tool update --global dotnet-ef
.csproj
file must reference the following nuget packages:
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Sqlite
dotnet ef dbcontext scaffold "Server=localhost;Database=DbName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Database -f --project C:\Dev\Something.csproj
dotnet ef dbcontext scaffold "DataSource='C:\ScrumTeamSqlLite3.db" Microsoft.EntityFrameworkCore.Sqlite -o Database -f --project C:\Dev\Something.csproj
Search for DbContext.cs
class
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = "Persist Security Info=False;User ID=*****;Password=*****;Initial Catalog=AdventureWorks;Server=MySqlServer";
optionsBuilder.UseSqlServer(connectionString);
}
This will allow us to see the SQL Queries being executed
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = "Persist Security Info=False;User ID=*****;Password=*****;Initial Catalog=AdventureWorks;Server=MySqlServer";
optionsBuilder.LogTo(Console.Write, LogLevel.Trace)
.EnableSensitiveDataLogging()
.EnableDetailedErrors()
.UseSqlServer(connectionString);
}