// disconnected existing entity
var student = new Student(){ StudentId = 1, StudentName = "Steve" };
using (var context = new SchoolDBEntities())
{
context.Entry(student).State = student.StudentId == 0? EntityState.Added : EntityState.Modified;
context.SaveChanges();
}