【问题标题】:EF Core BulkInsert 'Object reference not set to an instance of an object.'EF Core BulkInsert \'对象引用未设置到对象的实例。\'
【发布时间】:2022-11-18 13:42:57
【问题描述】:

我的 EF Core BulkInsert 在插入超过 80 行时抛出错误,下面是插入 80 行数据的示例
Insert 80 rows

但是当我尝试 100 行时,错误如图所示 Error message

我使用 JSON 作为数据

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;

}

知道这段代码有什么问题吗?为了 80行运行正常,超过80行报错如上

【问题讨论】:

    标签: asp.net-mvc entity-framework-core ef-bulkinsert


    【解决方案1】:

    有时它还取决于您使用的是哪个参数...

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

    在这里你写了数据:{数据: _o地震 }, 所以,在后端,它必须有类似下面的东西......

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

    注意:看参数名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      相关资源
      最近更新 更多