Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # *** Replace tokens in {curly braces} and run the command to reverse engineer database
- C:\Users\{your-username-here}\.dotnet\tools\dotnet-ef.exe dbcontext scaffold "server={your-server-here};Database=Task07;User={your-username-here};Password={your-password-here};TrustServerCertificate=True;MultipleActiveResultSets=true" Microsoft.EntityFrameworkCore.SqlServer -o Models
- # *** Open models in Visual Studio, find and open db context and find OnConfiguring method
- // *** Add the following section to appsettings.json - replace tokens in {curly brace} with the connection string found in OnConfiguring method ***
- "ConnectionStrings": {
- "AudioConnStr": "{copy-from-onconfiguring-method}"
- }
- // *** In OnConfiguring(), replace hardcoded conn. str. with the configuration parameter. Also, remove the big #warning, we don't need it any more.
- protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
- => optionsBuilder.UseSqlServer("Name=ConnectionStrings:AudioConnStr");
- // *** Register the db context in the DI container ***
- builder.Services.AddDbContext<Task07Context>(options =>
- {
- options.UseSqlServer("name=ConnectionStrings:AudioConnStr");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement