I am taking a tutorial on getting started with Entity Framework and C#. I was following the [tutorial][1] and I am getting an error when I tried to create a new scaffolding item. When I select the Model class, data context class and select the controller name, I get the following error message: "There was an error running the selected code generator: 'There was an error getting the type 'ContosoUniversity.Models.Student'. Try rebuilding the project."
I did rebuild the project, twice actually, and I keep getting this error message. Can anybody tell me what might be happening?
These are the steps I took to create the new scaffold item:
Right-click the Controllers folder in Solution Explorer, select Add, and then click New Scaffolded Item.
In the Add Scaffold dialog box, select MVC 5 Controller with views, using Entity Framework, and then choose Add. In the Add Controller dialog box, make the following selections, and then choose Add:
Model class: Student (ContosoUniversity.Models). (If you don't see this option in the drop-down list, build the project and try again.)
Data context class: SchoolContext (ContosoUniversity.DAL).
Controller name: StudentController (not StudentsController).
Leave the default values for the other fields.
This is how I have the code set up in my Student class file, under Models:
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 virtual ICollection<Enrollment> Enrollments { get; set; } } }
Finally, this is how I have my connections set up to the localDB that is being used in the tutorial.
> <connectionStrings>
> <add name="SchoolContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial
> Catalog=ContosoUniversity1;Integrated Security=SSPI;"
> providerName="System.Data.SqlClient"/> </connectionStrings>
Change your connection string
From this
To this