Skip to content

SQL Server bulk insert broken when new command applies pending commands and goes over the batch parameter limit #29539

@gaglia

Description

@gaglia

Hi,

I'm experiencing strange behavior using EF 7 with the generated SQL to perform the insert on database.

When I go to save a series of tables through SaveChanges two records of a table are not inserted in the SQL Server database.
From my first analysis it seems that the problem occurs when there is a consistent number of records to insert for the same table so that the SQL generated by EF 7 is broken into different inserts.

Analyzing with SQL Server Profiler I found that two of these inserts are not created correctly in the SQL generated by EF 7
therefore only 64 records are inserted on 66 entities of type veDocumenti_Righe

I have attached the detail of the DbContext before the SaveChanges where you can see that there are all 66 entities in the state of Added

However, analyzing the generated SQL code, I saw that for the two rows that are not actually inserted, the insert statement in the database is missing.
If you analyze the sql code that I attached in the SQLInsert01.sql file you will see that for example the @p2165 parameter is declared and valued correctly but is not then used in the insert

I await your kind feedback
Thank you

Provider and version information

EF Core version: 7.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Win11
IDE: Visual Studio 2022 17.4

SQLServerProfiler_Insert.zip

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions