c# - Inserting method differences between EF4/6 -


i began using ef6. in past insert object, code fake example (i'm writing medical software, hence, vitals) :

using (databasethingy objectcontext = new databasethingy(connection)) {      vitals pcrvital =  vitals.createvital(0, pcrentity.idpcr, timetaken, pulse);      objectcontext.vitals.addobject(pcrvital);      objectcontext.savechanges();      return pcrvital; } 

now read tells me so:

using (databasethingy objectcontext = new databasethingy(connection)) {     vitals pcrvital = new vitals(){              idvitals = 0,              idpcr = pcrentity.idpcr,              timetaken = timetaken,              pulse = pulse     };     objectcontext.vitals.add(pcrvital);     objectcontext.savechanges();     return pcrvital; } 

the first method not exist when use ef6. benefit first method auto create constructor minimum (non nullable) columns (edit) if edmx generated off of existing database. simple thing go check database see required, having list auto put constructor quite wonderful.

does know reason behind this, or if i've failed find has moved to?

in ef4 objectcontext used compared ef6 uses dbcontext. t4 templates generated code behind different between these versions , the earlier default constructor not available more.

the poco classes created in ef6 lighter , cleaner existed in ef4. afraid have live doing yourself.

you can still access objectcontext in ef6 below code , access methods addobject.

(dbcontext iobjectcontextadapter).objectcontext 

however need not anymore. better approach use dbset available in dbcontext add operations.

note: there t4 templates available can give earlier class structure ef6, though may not recommended.

ef6 entity object generator


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -