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