C# 由于实体框架核心中的循环依赖关系导致InvalidOperationException

C# 由于实体框架核心中的循环依赖关系导致InvalidOperationException,c#,sql,entity-framework,entity-framework-core,C#,Sql,Entity Framework,Entity Framework Core,当我尝试保存具有一对一关系的实体时,我收到以下InvalidOperationException: System.InvalidOperationException:无法保存更改,因为 在要保存的数据中检测到循环依赖关系:“ForeignKey: DeviceLicenseSubscriptionPlan{'LicenseId'}->DeviceLicense{'Id'} 唯一主题原则:许可证,外国密钥:DeviceLicense {'SubscriptionPlanId'}->DeviceLi

当我尝试保存具有一对一关系的实体时,我收到以下InvalidOperationException:

System.InvalidOperationException:无法保存更改,因为 在要保存的数据中检测到循环依赖关系:“ForeignKey: DeviceLicenseSubscriptionPlan{'LicenseId'}->DeviceLicense{'Id'} 唯一主题原则:许可证,外国密钥:DeviceLicense {'SubscriptionPlanId'}->DeviceLicenseSubscriptionPlan{'Id'} TopPrincipal:订阅计划'

这是我的模型:

public class DeviceLicense
{
    public Guid? Id { get; set; }
    public int DeviceLimit { get; set; }
    public DeviceLicenseSubscriptionPlan SubscriptionPlan { get; set; } = new DeviceLicenseSubscriptionPlan();
}

public class DeviceLicenseSubscriptionPlan 
{
    public Guid? Id { get; set; }
    public Guid? LicenseId { get; set; }
    public DeviceLicense License { get; set; }
}
下面是关于ModelCreating()的

模型创建时受保护的覆盖无效(ModelBuilder ModelBuilder)
{
var deviceLicense=modelBuilder.Entity().ToTable(“deviceLicense”);
HasKey(l=>l.Id);
deviceLicense.HasOne()
.有一个(s=>s.License)
.HasForeignKey(s=>s.LicenseId)
.HasConstraintName(“被许可方ID”);
属性(l=>l.DeviceLimit).HasColumnName(“DeviceLimit”);
var deviceLicenseSubPlan=modelBuilder.Entity().ToTable(“DeviceLicenseSubscriptionPlan”);
deviceLicenseSubPlan.HasKey(s=>s.Id);
deviceLicenseSubPlan.Property(s=>s.Id).HasColumnName(“SubscriptionPlanId”);
基于模型创建(modelBuilder);
}

我正在使用EF Core 2.0。我可能在ModelBuilder中做错了什么?有什么提示吗?

问题出在这行

deviceLicense.HasOne<DeviceLicenseSubscriptionPlan>()

问题是这条线

deviceLicense.HasOne<DeviceLicenseSubscriptionPlan>()
deviceLicense.HasOne(l => l.SubscriptionPlan)