我想插入一條記錄,然後根據插入記錄的scope_identity更新記錄。 我正在這樣做,但是當我想更新我的記錄時遇到錯誤。根據LINQ中插入記錄的ID更新記錄到SQL
WorkshopDataContext Dac = new WorkshopDataContext();
Dac.Connection.ConnectionString = "Data Source=dpsxxx-xxx;Initial Catalog=kar;User ID=sa;Password=xxxx";
Tbl_workshop Workshop = new Tbl_workshop();
Workshop.StateCode = Bodu.BduStateCode;
Workshop.CityCode = Bodu.BduCityCode;
Workshop.Co_workshop=12222;
Dac.Tbl_workshop.InsertOnSubmit(Workshop);
Dac.SubmitChanges();
Int64 Scope = Workshop.id;
var query = from record in Dac.Tbl_workshop where record.id == Scope select record;
query.First().co_Workshop = Scope;
Dac.SubmitChanges();
,這是錯誤:
Value of member 'co_Workshop' of an object of type 'Tbl_Workshop' changed.
A member defining the identity of the object cannot be changed.
Consider adding a new object with new identity and deleting the existing one instead.
否'Co_Workshop'不是身份,它只是主鍵 – 2011-05-08 15:00:00
然後檢查Linq DBML,也許它不同步 – ariel 2011-05-08 15:01:35
我檢查了它,沒關係。我是否正在更新?我在'co_kargah'中插入了12222的值,並且在插入記錄後,我想用同一個表中的插入記錄的'id'更新它 – 2011-05-08 15:05:40