MyProject.Controllers.CurrencyCodesController Unable to update the EntitySet 'CurrencyCodes' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. System.Data.Entity.Infrastructure.DbUpdateException: Unable to update the EntitySet 'CurrencyCodes' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. ---> System.Data.Entity.Core.UpdateException: Unable to update the EntitySet 'CurrencyCodes' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. |
Scenario: The error occured while trying to insert the currencycodes entity to the database. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "cucCurrencyCode,cucDescription,cucMultiplier,cucRate,cucInUse")] CurrencyCode currencyCode) { if (ModelState.IsValid) { try { db.CurrencyCodes.Add(currencyCode); db.SaveChanges(); } catch (Exception ex) { log.Error(ex.Message, ex); } return RedirectToAction("Index"); } return View(currencyCode); } 1) Check Primary key in .edmx file. In my case cucInUse was set as Entity key. I removed it. 2) Now Right click the .edmx file and click "Open with...". Select XML (text) Editor 3) Find the element <EntitySet name = "CurrencyCodes"...> 4) Change store:Schema="dbo" => Schema="dbo" 5) delete element <DefiningQuery> 6) Clean the project. 7) close Visual studio. 8) Open visual studio. Open the project. 9) Clean and build the project. 10) Run the application. |
Thursday, 2 July 2020
EntityFramework Insert error due to PrimaryKey
Subscribe to:
Post Comments (Atom)
Create a Directory from existing disk in proxmox server
Scenario: I have an NVMe disk with an ext4 partition that was previously used as a directory in a Proxmox server. After reinstalling Proxm...
-
This solution Works for TFS 2010+ . Open Visual studio Command prompt and run the following script. tf workspace /delete /server:[Site:Port/...
-
for example, the login name is 'mysqluserlogin' 1) Enable the disabled login: ALTER LOGIN mysqluserlogin ENABLE ; 2) Change the lo...
-
Problem 1) 2019-07-02T14:19:12.5157398Z fatal: unable to access 'https://tfssite.company.com/tfs/UK_ProjectCollection/SalesPortal/_git/S...
No comments:
Post a Comment