我有一個實體Locations
,其主鍵由Longitude
和Latitude
組成double
。如何從Entity Framework中將實體對象的引用移除到另一個實體?
從另一個實體對象中,我想刪除對Locations
中實體對象的引用,但每次嘗試將引用設置爲null時,我都會得到一個OptimisticConcurrencyException
。
using (MyModelContainer context = new MyModelContainer())
{
Note note = context.Notes.Single(n => n.NID == NoteUpdate.NID);
note.LocationReference.Load();
note.LocationReference = null;
context.saveChanges();
}
但它不工作。 note.LocationReference.Value = null
也是如此。
如何將參考設置爲null或其默認值?
你能爲註釋和位置顯示你的模型嗎? – 2012-03-07 21:11:42
'Location'和'Note'在0..1到很多關係中。 「位置」的主鍵爲「經度」,「緯度」爲「雙」。 '筆記'有一個標題,一個內容和一個ID。 – flyinggecko 2012-03-07 21:31:35
你有沒有設置任何級聯刪除/更新? – RichardW1001 2012-03-07 22:21:00