以現有資料庫產生EF架構,有時候會發現,在寫入資料時會有不明原因的報錯
錯誤訊息 Error “You have an error in your sql syntax entity framework” with Entity Framework
目前查到的解決方法如下:
1. 右鍵點擊產生的edmx檔,用有編碼的xml打開
2. 搜尋
DefiningQuery 這個Tag,然後把它砍了
3. 之後就一切正常了
參考網頁
What happened is that at the moment of executing db.SaveChanges()
(after an update), the .edmx tried to update the rows in the 'C' table, but as this table only had two foreign keys to A and B, the update operation wasn't supported. This is the solution that I found in other post in StackOverflow, and it worked for me:
- Right click on the edmx file, select Open with, XML editor
- Remove the DefiningQuery entirely
- Rename the
store:Schema="dbo"
to Schema="dbo
(remove the "store:")
- Remove the
store:Name=...
property (entirely)