entity framework - Edit model data after EF6 add -


usually tipical ef6 add should be

var newstudent = new student(); newstudent.studentname = "bill"; context.students.add(newstudent); context.savechanges(); 

in case i'm using logic

var student = context.students.find(id); if (student == null) {     student = new student();     context.students.add(student ); } student.blabla1 = "..."; student.blabla2 = "..."; //other 20 blabla... student.studentname = "bill"; // studentname required field context.savechanges(); 

it's bad practise edit data model after add method on entity framework 6? context injected can thrown error on case savechanges called on method , actual thread before assignment of "studentname"?

why can't ...

   var student = context.students.find(id);     if (student == null)     {         student = new student();         modifyblabla(student );//call private method         context.students.add(student);     }   else    {      modifyblabla(student );//call private method    }      context.savechanges(); 

method edit :

private void modifyblabla(student student) {    student.blabla1 = "...";    student.blabla2 = "...";    //other 20 blabla...    student.studentname = "bill"; } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -