How to Fix "Unable to update the EntitySet" Error

如果你嘗試對資料表實體集進行新增、修改、刪除資料時,有可能會發生無法更新實體集的例外狀況。以下是更新資料時所引發的錯誤訊息:
System.Data.UpdateException: 無法更新 EntitySet '實體集名稱',因為它有 DefiningQuery,但是在 <ModificationFunctionMapping> 項目中沒有 <UpdateFunction> 項目來支援目前的作業。

Unable to update the EntitySet 'EntitySet Name' because it has a DefiningQuery and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

當你將不含主索引鍵的資料表加入實體資料模型(Entity Data Model,EDM)時,Entity Framework 會因為找不到資料表主索引鍵,而將定義建立成唯讀的資料表,也就是在描述儲存結構之 SSDL 區段所定義的 EntitySet 項目中,加入 DefiningQuery 項目以對應到資料存放區的唯讀檢視。所以,當實體集使用定義查詢時,你就無法使用標準更新處理序將保存更新至資料來源。如果嘗試對唯讀的實體集進行更新動作,將會引發如上所述的例外狀況。

要解決這個問題,你可以為來源資料表加入主索引鍵,並透過更新資料庫模型來獲得解決。或者,你也可以利用實體資料模型支援使用預儲程序的功能,定義插入、更新、刪除函式對應來進行資料更新。


Share/Save/Bookmark

0 comments :: How to Fix "Unable to update the EntitySet" Error

張貼留言