Erro:
Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions' while attempting to activate 'ScreenSound.Banco.ScreenSoundContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=85172
Class de contexto:
using Microsoft.EntityFrameworkCore; using ScreenSound.Shared.Modelos.Modelos;
namespace ScreenSound.Banco;
public class ScreenSoundContext : DbContext { private readonly string connectionString = "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ScreenSoundV0;Integrated Security=True;Encrypt=False;Trust Server Certificate=False;Application Intent=ReadWrite;Multi Subnet Failover=False";
public DbSet<Artista> Artistas { get; set; }
public DbSet<Musica> Musicas { get; set; }
public DbSet<Genero> Generos { get; set; }
public ScreenSoundContext(DbContextOptions options): base (options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured)
{
return;
}
optionsBuilder
.UseSqlServer(connectionString)
.UseLazyLoadingProxies();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Musica>()
.HasMany(c => c.Generos)
.WithMany(c => c.Musicas);
}
}