You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure at all if this is a bug. At least I think is an unexpected behavior.
This behavior appeared for the first time after migrating to NET 6. I've managed to reproduce the issue in the simple project composed of the 3 files shown bellow. First I thought it was a breaking change so I reviewed all of them. However, I'm unable to find any breaking change that would cause this error. As I wasn't able to relate the error to any change I started changing efcore version in my .csproj file. As soon as I change to 6.0.0-rc.2.21480.5 for all the packages (efcore) the error doesn't show anymore. Another thing to highlight is that if I add a SaveChanges after the removes in the program.cs file the error won't happen either.
Person.cs
#nullable disable
publicclassPerson{publicintPersonId{get;set;}publicstringName{get;set;}publicint?ParentId{get;set;}publicPersonParent{get;set;}protectedPerson(){}publicPerson(stringname,Personparent){this.Name=name;if(parentis not null){this.Parent=parent;}}}
Unhandled exception. System.InvalidOperationException: Unable to save changes because a circular dependency was detected in the data to be saved: 'Person [Deleted]Person [Deleted] Parent { 'ParentId' } <-
Person [Deleted] Parent { 'ParentId' } <-
Person [Deleted]To show additional information call 'DbContextOptionsBuilder.EnableSensitiveDataLogging'.'.
at Microsoft.EntityFrameworkCore.Utilities.Multigraph`2.ThrowCycle(List`1 cycle, Func`2 formatCycle, Func`2 formatException)
at Microsoft.EntityFrameworkCore.Utilities.Multigraph`2.BatchingTopologicalSort(Func`4 tryBreakEdge, Func`2 formatCycle)
at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.TopologicalSort(IEnumerable`1 commands)
at Microsoft.EntityFrameworkCore.Update.Internal.CommandBatchPreparer.BatchCommands(IList`1 entries, IUpdateAdapter updateAdapter)+MoveNext()
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c.<SaveChanges>b__104_0(DbContext _, ValueTuple`2 t)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
at Program.<Main>$(String[] args) in C:\Users\Dev04\Desktop\Nueva carpeta\test\Program.cs:line 44
Version information
EF Core version:
Ef Core (Microsoft.EntityFrameworkCore 6.0.0)
Database provider: (Microsoft.EntityFrameworkCore.SqlServer 6.0.0)
Target framework: (.NET 6.0.0)
The text was updated successfully, but these errors were encountered:
I'm having the same issue in my project after the upgrade. Does it have any known workaround until a fix is released?
in my situation, I add another context.SaveChanges() before add, it works.
Description
I'm not sure at all if this is a bug. At least I think is an unexpected behavior.
This behavior appeared for the first time after migrating to NET 6. I've managed to reproduce the issue in the simple project composed of the 3 files shown bellow. First I thought it was a breaking change so I reviewed all of them. However, I'm unable to find any breaking change that would cause this error. As I wasn't able to relate the error to any change I started changing efcore version in my .csproj file. As soon as I change to 6.0.0-rc.2.21480.5 for all the packages (efcore) the error doesn't show anymore. Another thing to highlight is that if I add a SaveChanges after the removes in the program.cs file the error won't happen either.
Person.cs
Context.cs
Program.cs
Stack trace
Version information
EF Core version:
Ef Core (Microsoft.EntityFrameworkCore 6.0.0)
Database provider: (Microsoft.EntityFrameworkCore.SqlServer 6.0.0)
Target framework: (.NET 6.0.0)
The text was updated successfully, but these errors were encountered: