5
我有表如何從實體框架更新主鍵?
eventid int -- not PK key but with autoincrement
jobid -- PK autoincrement disabled
userid int -- PK autoincrement disabled
要更新作業ID我以下:
var itemforupdate = context.table.where(n=>n.eventid == someparameter).FirstorDefault()
我從數據庫中獲取的項目正確,但分配時:
itemforupdate.jobID = 5;
context.SaveChanges();
後context.SaveChanges()
我得到的錯誤:
The property 'jobID' is part of the object's key information and cannot be modified
如何從實體框架更新jobID來解決這個問題?
我不是實體框架的專家,但不能將對象的關鍵字設置爲eventid(因爲它是一個自動增量列)? –
我剛剛從數據庫中使用Eventid的唯一併試圖從EF更新jobid,但它給出錯誤 – R01
Duplicate:http://stackoverflow.com/questions/1367751/update-primary-key-value-using-entity -framework – Ulric