-1

My EF Core BulkInsert throws error when inserting more than 80 rows, below is the example insert 80 rows data
Insert 80 rows

but when i try 100rows the error as shown

System.NullReferenceException: 'Object reference not set to an instance of an object.'

Im using JSON for the data

function Save() {
    var fail = {
        title: 'Data insert fail',
        message: 'refresh page to save again',
        position: 'topRight'
    };
    console.log(_oSeismics);
    if (_oSeismics.length > 0) {
        var ajaxRequest = $.ajax({
            url: "../PmepTempAdd/SavePmepVSP/",
            type: "POST",
            data: { data: _oSeismics },
            dataType: "json",
            beforeSend: function () {
            },
        });

        ajaxRequest.done(function (data) {

            swal('Success!', 'Successfully saved.', 'success');

        });

        ajaxRequest.fail(function (jqXHR, textStatus) { 
            iziToast.error(
                    fail
                ); 
        });

    }

    else {

        iziToast.error(
                    fail
                );

    }

}

function NewSeismicObj() {
    var now = new Date();
    var date = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
    var time = now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
    var dateTime = date + ' ' + time;

    console.log(dateTime)
    
    var oSeismic = {
        
        No: "",
        WellName: "",
        SurveyVspYaTdk: "",
        VspSonicCalibrationSynthetic: "",
        VspReport: "",
        VelocityWellCheckshot: "",
        WellProgramProposal: "",
        FinalWellReportEndOfWellReport: "",
        ProcessingDataSgy: "",
        RawDataSgy: "",
        Recommendation: "",
        RowCreated: dateTime
            
    };console.log(dateTime)

    return oSeismic;

}

Any Idea whats wrong with this code? for 80 rows runs normal, but over 80 error shown as above

Edit :

I have tried to change parameter into data but still error

PmepTempAddController.cs code

public JsonResult SavePmepVSP(List<VerTempPmepSeismicVsp> data)
    {
        _VSPt = _db.SavePmepSeismicsVSP(data);
        TempData["success"] = "Inserted to TempPmeporary Table successfully";
        return Json(_VSP);
    }

Service.cs code

    public List<VerTempPmepSeismicVsp> SavePmepSeismicsVSP(List<VerTempPmepSeismicVsp> data)
    {
        _dbContext.BulkInsert(data);
        return data;
    }
KimKim
  • 21
  • 8

1 Answers1

0

Sometimes Its also depends on which parameter are you using...

 var ajaxRequest = $.ajax({
            url: "../PmepTempAdd/SavePmepVSP/",
            type: "POST",
            data: { data: _oSeismics },
            dataType: "json",
            beforeSend: function () {
            },
        });

here you have written data: { data: _oSeismics }, So, in the backend, it must have something like the below...

public List<VerTempPmepSeismicVsp> SavePmepVSP( List<VerTempPmepSeismicVsp> data) 

Note: Look at the name of parameter.

  • updated on the question, but still error. actually i send the json into controller first before to service file here is the code `public JsonResult SavePmepWGI(List data) { _WGIt = _db.SavePmepWGI(data); TempData["success"] = "Inserted to TempPmeporary Table successfully"; return Json(_WGIt); }` – KimKim Nov 18 '22 at 05:33
  • @KimKim are you getting data in controller while calling from ajax ? – Prince Gajjar Nov 18 '22 at 06:36
  • yes, ajax into controller into service – KimKim Nov 18 '22 at 07:14
  • then you can try something like `List obj = new List(); obj = data;` and then `_dbContext.BulkInsert(obj);` – Prince Gajjar Nov 18 '22 at 09:50