首页 > 解决方案 > EF Core InMemory 未抛出:无法保存更改,因为检测到循环依赖

问题描述

我们有一个类似于https://github.com/aspnet/EntityFrameworkCore/issues/11888中的模型。

就像上面的问题一样,当使用 SqlServer 执行此操作时,我们会遇到异常 Unhandled Exception: System.InvalidOperationException: Unable to save changes because a circular dependency was detected in the data to be saved: 'Person [Added] <- Owner { 'OwnerId' } Car [Added] <- ActiveCar { 'ActiveCarId' } Person [Added]'.

但是,当我们使用 InMemory 数据库进行单元测试时,不会引发此异常。有没有办法通过内存数据库获得这个异常?

标签: c#entity-frameworkentity-framework-core

解决方案


推荐阅读