Hi,
I have knowledge about db connectivity for MVC. But i want to know actual process using entity framework. Please suggest best link for learn.
Regards
Hemlata
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Santhakumar MunuswamyPosted Sep 2, 2015, 3:45 PM
Shibly SadikPosted Sep 2, 2015, 12:33 PM
Create a model class named Student under Model folder and write the follwing code inside the model:
public class Student
{
public int StudentId {get;set;}
public string Name {get;set;}
public string Roll {get;set;}
public string Dept {get;set;}
}
public class StudentContext:DbContext
{
public DbSet
}
//Add a controller Named StudentController
public class StudentController:Controller
{
StudentContext db=new StudentContext();
public ActionResult AddStudent(Student student)
{
if(ModelState.isValid)
{
db.Students.add(student);
db.SaveChanges();
}
}
}
Now rebuild the project.Open the View folder.Right click on Student Folder.Select Add and then choose View.Give the view name AddStudent.Select Create template.Select model Student and choose database context s StudentContext.Click Add.You are done.Run your project.
This may help you.
Francis SusaimichaelPosted Sep 2, 2015, 4:15 AM
Harshad PansuriyaPosted Sep 2, 2015, 2:39 AM