I am using the code first approach to create the schema and then populating the data in it with the help of Seed method
I am using Entity Framework Version 5.0,SQLEXPRESS2008 and MVC4
below is my Model
public enum Grade
{
A, B, C, D, F
}
public class Enrollment
{
public int EnrollmentID { get; set; }
public int CourseID { get; set; }
public int StudentID { get; set; }
[DisplayFormat(NullDisplayText = "No grade")]
public Grade? Grade { get; set; }
public virtual Course Course { get; set; }
public virtual Student Student { get; set; }
}
this is how i populate the data to the Database using seed method in Intializer
var enrollments = new List<Enrollment>
{
new Enrollment{StudentID=1,CourseID=1050,Grade=Grade.A},
new Enrollment{StudentID=1,CourseID=4022,Grade=Grade.C},
new Enrollment{StudentID=1,CourseID=4041,Grade=Grade.B},
new Enrollment{StudentID=2,CourseID=1045,Grade=Grade.B},
new Enrollment{StudentID=2,CourseID=3141,Grade=Grade.F},
new Enrollment{StudentID=2,CourseID=2021,Grade=Grade.F},
new Enrollment{StudentID=3,CourseID=1050},
new Enrollment{StudentID=4,CourseID=1050,},
new Enrollment{StudentID=4,CourseID=4022,Grade=Grade.F},
new Enrollment{StudentID=5,CourseID=4041,Grade=Grade.C},
new Enrollment{StudentID=6,CourseID=1045},
new Enrollment{StudentID=7,CourseID=3141,Grade=Grade.A},
};
enrollments.ForEach(s => context.Enrollments.Add(s));
context.SaveChanges();
on debug ,I am able to see the data in "Grade" Column within that context
but it neither creates the Column "Grade" in Database nor populates its data.
I have setup the Context and Database Initalizer as below in my web.config
<entityFramework>
<context type="EntityFrameworkWithMVC.DAL.SchoolContext, EntityFrameworkWithMVC">
<databaseInitializer type="EntityFrameworkWithMVC.DAL.SchoolInitializer, EntityFrameworkWithMVC" />
</context>
</contexts>
</entityFramework>
Gradecolumn that's missing? Did you add it after an initial database creation? If so; try to recreate the database by deleting it manually. If theGradefield is created, it must be you migration strategy. Final thing: are you using .NET 4.5? it is required for theenumfunctionality in EF5