Circular dependency while creating tables with DatabaseFacade.EnsureCreated on EF Core 6 #26834
Labels
area-migrations
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
regression
Servicing-approved
type-bug
Milestone
We use a Database-First approach to generate DbContext from a SqlServer database. However, we also use Model-First in unit tests to generate an in-memory Sqlite database.
Everything works fine on EF Core 5 but we've been struggling to upgrade to EF Core 6 due to a "circular dependency" error while creating database tables using the
EnsureCreated
method. Searching on the web for this error usually leads toSaveChanges
errors while saving entities with circular references to the database so I couldn't find anything related to database creation.GenerateCreateScript
also causes the same issue. I used this method to test the issue against SqlServer to see if it is related to Sqlite but it doesn't seem to be. The error is fromMultigraph.cs
while trying to do topological sort. For some reason, it is not able to break cycles in our model and ends up with this error.This issue does not reproduce on EF Core 5. Simply change
6.0.0
to5.0.12
inEFCoreTest.csproj
shared below to confirm it doesn't fail.Include your code
Here is a simple project that reproduces the issue:
EFCore6Test.tar.gz
We have more than 200 entities in our model so I tried to simplify it and got a repro involving 7 entities.
Program.cs:
SampleContext.cs:
Include stack traces
Include provider and version information
EF Core version: 6.0.0
Database provider: Sqlite (Microsoft.EntityFrameworkCore.Sqlite 6.0.0)
Target framework: .Net 6.0.100
Operating system: Debian
The text was updated successfully, but these errors were encountered: