Base solution for your next web application
Open Closed

Bulk Insert #11929

User avatar
muhittincelik created


I got 3376 record from a query and i want to insert this result to my application;

I am using 13.1.1

Code is;

var ajaxResponse = JsonConvert.DeserializeObject<UCMDBCis>(content);
int i = 0;
foreach (UCMDBContent data in ajaxResponse.Cis)
    var filteredHostname = _stageHostRepository.GetAll()
                            .WhereIf(!string.IsNullOrWhiteSpace(data.Properties.Name), e => false || e.Hostname.Contains(data.Properties.Name))

    if (filteredHostname.GetEnumerator().MoveNext() == false)
       CreateOrEditStageHostDto stageHost = new CreateOrEditStageHostDto();

        stageHost.FeedSourceId = filteredFeedSource.FirstOrDefault().Id;
        stageHost.Hostname = data.Properties.Name;



    if (i == 500) { break; }

This code is running successfully. But where i remove 500 record count segment i got the following error;

Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated. at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

How can i insert thousands of records ?

1 Answer(s)
  • User Avatar
    muhittincelik created

    I solved the problem. Its about source data column size. It is not releated to row count.