c# - How to get the primary key of an object after it is saved with DbContext -
given out of context snippet of code:
var calibration = new calibration { calibrationtype = selectedtest.testtypeid ,expiration = expirationdate ,lastsaved = datetime.now ,statustypeid = 1 ,technicianid = selectedtechnician.id ,phases = buildcalibrationphases() }; db.calibrations.add(calibration); db.savechanges();
is there way entity framework primary key chosen(seeded) calibration object after db.savechanges();
completes?
in other words how can primary key object after committed?
reload entry in context:
db.entry(calibration).reload();
then can access newly created pk
Comments
Post a Comment