En program.cs
// Add services to the container. builder.Services.AddControllersWithViews(); // Añadimos la conexión al contexto builder.Services.AddDbContext<Contexto>(options => options.UseSqlServer("Data Source=.\\SQLEXPRESS;Initial Catalog=clase;Integrated Security=True;TrustServerCertificate=True")); var app = builder.Build();
En contexto.cs:
public DbSet<Alumno> Alumnos { get; set; } public Contexto(DbContextOptions<Contexto> options) : base(options) { }