CRUD with EF returning null param to Controller (Column identity SQL Auto increment)

Hello,

How to fix the insertion problem in SQL EXPRESS Database with CRUD operation with AUTO INCREMENT column, (Update and delete operations) works fine.

I tried in the view to assign a value to AUTO INCREMENT Column (“Numero”), the <param> is not null but I get SQL error : SqlException : Cannot insert explicit value for identity column in table '' when IDENTITY_INSERT is set to OFF.
Thanks.
Below some information about this problem.

In the Controller :

public ActionResult InsertRemind([FromBody]CRUDModel<RappelsData> param)
        {
            db.RappelsDatas.Add(param.Value);
....
Param is null



In the Class Model :

 public class RappelsData
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Numero { get; set; }....
               //....


In the view

<ej-grid id="FlatGrid" is-responsive="true" allow-paging="true" action-complete="complete" action-begin="onBegin" record-double-click="onRecordDblClick" allow-text-wrap="true">
            <e-datamanager json="(IEnumerable<object>)ViewBag.datasource" update-url="/Reminders/UpdateRemind" remove-url="/Reminders/DeleteRemind" insert-url="/Reminders/InsertRemind" adaptor="remoteSaveAdaptor" />
            <e-edit-settings allow-adding="true" allow-deleting="true" allow-editing="true" show-delete-confirm-dialog="true" edit-mode="InlineFormTemplate" inline-form-template-id="#template" />
            <e-toolbar-settings show-toolbar="true" toolbar-items="@(new List<string>() {"add","edit","delete","update","cancel" })"></e-toolbar-settings>
            <e-columns>
                <e-column field="Numero" header-text="No" is-primary-key="true" is-identity="true" allow-editing="false" text-align="Left" width="40"></e-column>
               //....
            </e-columns>
        </ej-grid>


SQL Definition Table

CREATE TABLE [dbo].[RappelsData] (
    [Numero]       INT           IDENTITY (1, 1) NOT NULL,
.....
  PRIMARY KEY CLUSTERED ([Numero] ASC)
//....



3 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team November 30, 2017 04:45 PM UTC

Hi Laid, 

Thanks for contacting Syncfusion Support. 

We have checked your query and your reported problem occurs when you are passing some value in a column which is set as identity (auto-increment). Also you cannot insert a value to it without IDENTITY_INSERT switched on for that field.  To resolve the problem You have to turn on identity insert on the table so that you can specify your own identity values.  

Please refer to the stack Overflow Link:- 



Please get back to  us if you need any further assistance. 

Regards, 

Farveen sulthana T 



LA LAID November 30, 2017 09:47 PM UTC

Hello,

I solved this problem. L’error is that I inserted the identity column <> into the template form inline-form-template-id ="#template"

<scriptid="template"type="text/x-jsrender">

<tablecellspacing="0"border="0"style="width:100%">

<tr>

<td>Numéro :td>

<td>

<inputid="Numero"name="Numero"value="{{:Numero}}"disabled="disabled"class="e-field e-ejinputtext"/>

td>

tr>


I deleted this section so, the param contains data in the insert action.

Thank you for your assistance



FS Farveen Sulthana Thameeztheen Basha Syncfusion Team December 1, 2017 10:43 AM UTC

Hi Laid, 
  
Thanks for your update.  Please get back to us if you need any further assistance. 
  
Regards, 
  
Farveen sulthana T 


Loader.
Up arrow icon