While updating parent entity, EF Core is deleting child entities

260 views Asked by At

I recently updated my project from ASP.NET Core 2.1 to 5.0, EF Core is removing the child entities once I try to update the parent entity.

Profiler response, when project project was running on ASP.NET Core 2.1:

exec sp_executesql N'SET NOCOUNT ON;
                     UPDATE [Table] SET [Title] = @p0
                     WHERE [Id] = @p1;
                     SELECT @@ROWCOUNT;',
                   N'@p1 int,@p0 int int',
                   @p1=5672,@p0='Test'

Profiler response after migration to ASP.NET Core 5:

exec sp_executesql N'SET NOCOUNT ON;
                     UPDATE [Table] SET [Title] = @p0
                     WHERE [Id] = @p1;
                     SELECT @@ROWCOUNT;
 
                     DELETE FROM [ChildTable]
                     WHERE [Id] = @p2;
                     SELECT @@ROWCOUNT;

                     DELETE FROM [ChildTable]
                     WHERE [Id] = @p3;
                     SELECT @@ROWCOUNT;

                     DELETE FROM [ChildTable]
                     WHERE [Id] = @p4;
                     SELECT @@ROWCOUNT;',
                   N'@p1 int,@p0 int, @p2 int,@p3 int,@p4 int int',
                   @p1=5672,@p0=N'Test!',@p2=5671, @p2=5672, @p3=5673

Startup.cs

 services.AddDbContext<DbContext>(options => options.UseSqlServer(this.Configuration.GetConnectionString("DefaultConnection"), o => o.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery)).EnableSensitiveDataLogging());
0

There are 0 answers