In my DataLayer I have this 'Seed' method:
protected override void Seed(Context context)
{
User u1 = new User()
{
UserName = "dayan",
Password = "dayan",
Role = "Admin"
};
User u2 = new User()
{
UserName = "neranjan",
Password = "neranjan",
Role = "employee"
};
context.Users.Add(u1);
context.Users.Add(u2);
base.Seed(context);
}
This how my User table looks like:
So now i need to add more table data into this seed method like this:
Examination e = new Examination()
{
Description = "fromda console",
CutOffMark = 1000,
QuestionID = new List<Question>()
{
new Question()
{
QuestionDes = "Question",
Answer1 = "11",
Answer2 = "22",
Answer3 = "33",
Answer4 = "44",
Correct = 1
}
}
};
the purpose i need this method to work is because i'm using the code-first entity framework therefore i need to make sure when i drop the the database and create the database again these rows should be written in those tables.
can you please give me an idea how to solve this problem... Thank You!!
this is how i solved it....
I'm working with MVC, so i found this file called 'Global.asax' in my MVC folder and i add this 'SetInitializer' to it. this is how it looked...
Then i runned my home page. the. it automatically inserted my data objects into the DB... this is how my homepage looks like....
Controller:
thank you!!!!