I am following this tutorial, using Visual Studio Community 2015 v 14.0.25431.01 Update 3 and MS .NET Framework v 4.6.91586, but get the following error when I attempt to scaffold the controller, as described:
I have tried all the suggested solutions here and here, but to no avail. Yes, also tried (re)building the project.
Here is the relevant code from my project.
Student Model:
using System;
using System.Collections.Generic;
namespace ContosoUniversity.Models
{
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
}
}
SchoolContext:
public class SchoolContext : DbContext
{
public SchoolContext(DbContextOptions<SchoolContext> options) : base(options)
{
}
public DbSet<Course> Courses { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
public DbSet<Student> Students { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Course>().ToTable("Course");
modelBuilder.Entity<Enrollment>().ToTable("Enrollment");
modelBuilder.Entity<Student>().ToTable("Student");
}
}
Added the SchoolContext to the services in startup.cs:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddDbContext<SchoolContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
And this is my connectionstring in appSetting.json:
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-ContosoUniversity-75b88406-9d10-4237-814a-3f725b9b4e3d;Trusted_Connection=True;MultipleActiveResultSets=true"
}