Error in SaveChanges () method

I am building an application using an Oracle database and ASP.net MVC4. Although there is no problem in the code, calling the SaveChanges() method causes the error shown here:

enter image description here

This image shows the internal exception and related details.

enter image description here

This is the implementation I made to save the changes.

 if (ModelState.IsValid) { ModelState.Clear(); using (SSP_Entities database = new SSP_Entities()) { database.REQUEST_TAB.Add(c_modal.Request_tab); database.SaveChanges(); caseID = c_modal.Request_tab.CASE_ID; return RedirectToAction("NewEnv", cpe); } } 

I use the following code in a view

  <%:Html.HiddenFor(model => model.request_tab.ROWVERSION, new { @Value="date"}) %> <%:Html.HiddenFor(model => model.request_tab.CASE_ID, new { @Value=100}) %> <%:Html.HiddenFor(model => model.request_tab.REQUEST_BY, new { @Value="PUSNLK"}) %> <%:Html.HiddenFor(model => model.request_tab.REQUEST_ID, new { @Value=334}) %> <%:Html.HiddenFor(model => model.request_tab.REQUEST_TYPE, new { @Value="CPE"}) %> <%:Html.HiddenFor(model => model.request_tab.STATE, new { @Value="POSTED"}) %> <%:Html.HiddenFor(model => model.request_tab.COMMENTS, new { @Value="CPE Order"}) %> 

This is the model I'm using.

 namespace CPEASPX.Models { using System; using System.Collections.Generic; public partial class REQUEST_TAB { public decimal REQUEST_ID { get; set; } public string REQUEST_BY { get; set; } public decimal CASE_ID { get; set; } public string STATE { get; set; } public string REQUEST_TYPE { get; set; } public string ROWVERSION { get; set; } public string COMMENTS { get; set; } } } 

I tried several solutions shown elsewhere. First I changed the <appSettings> web.config in web.config by adding

 <add key="aspnet:MaxHttpCollectionKeys" value="5000" /> <add key="aspnet:MaxJsonDeserializerMembers" value="5000" /> <add key="aspnet:MaxHttpCollectionKeys" value="10000" /> 

. But the problem continues. I cannot find a mismatch between the client and server data types.

Please help me deal with the problem.

Here im passes two models in one view. I created the following combined model for this (c_model is an object of this class)

 using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace CPEASPX.Models { public class CombineModal { public REQUEST_TAB request_tab = new REQUEST_TAB(); public REQUEST_TAB Request_tab { get { return request_tab; } set { request_tab = value; } } public CPE cpe = new CPE(); public CPE Cpe { get { return cpe; } set { cpe = value; } } } } 

it says here that I pass him the CPE model, but I only go through the combined model that contains CPE modal and Request_tab modal.

this is the code i use in a view to inherit a modal class

 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CPEASPX.Models.CombineModal>" %> 
+2
source share
1 answer

I think you need to assign each property instead of adding an entire class.

 using (SSP_Entities database = new SSP_Entities()) { var requestTab = new RequestTab { REQUEST_ID = c_modal.Request_tab.REQUEST_ID, REQUEST_BY = c_modal.Request_tab.REQUEST_BY, CASE_ID = c_modal.Request_tab.CASE_ID, STATE = c_modal.Request_tab.STATE, REQUEST_TYPE = c_modal.Request_tab.REQUEST_TYPE, ROWVERSION = c_modal.Request_tab.ROWVERSION, COMMENTS = c_modal.Request_tab.COMMENTS }; database.REQUEST_TAB.Add(requestTab); database.SaveChanges(); } 
+1
source

Source: https://habr.com/ru/post/1209091/


All Articles