我認爲你需要將它們兩個提交到一起,以便它們在同一個事務中。那麼不需要編寫回滾代碼,因爲如果細節失敗,主服務器不會被插入。 試試這個:
master objmaster= new master();
objmaster.id =count;
objmaster.name= name1;
..
objEntities.AddObject("master", objmaster);
// == removed save changes call here ==
detail objDetail = new detail()
// == no need to reselect master from the database, you already have it
// == so just assign it, and that will take care of the references/foreign-key
objDetail.master = objMaster; // Suppose I get any (format, null pointer exception here)
objDetail.folow = sfields[0]; //In case of exception this below code will not be excecuted
objEntities.AddObject("detail", objDetail);
// == save at the end ==
objEntities.SaveChanges();
沒有數據插入子表,當我準備從主表中刪除: – 2010-10-01 13:58:23
它不給予任何驗證錯誤,這是給不能刪除其中的外鍵關係的錯誤存在。 – 2010-10-01 13:59:56
你打電話給一個孩子和家長的提交變更,或者兩者都被分開保存到數據庫 – Tassadaque 2010-10-01 14:11:11