Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

entity save example in c# model first

// 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();
}
Source by www.entityframeworktutorial.net #
 
PREVIOUS NEXT
Tagged: #entity #save #model
ADD COMMENT
Topic
Name
2+5 =