我的数据模型
Table("People")]
public abstract class Person
{
public long Id { get; set; }
public string Name { get; set; }
[ForeignKey("ReferredBy")]
public long? ReferredById { get; set; }
public User ReferredBy { get; set; }
}
public class User : Person
{
public string UserName { get; set; }
}
public class Student : Person
{
public string RollNo { get; set; }
}
Fluent API在删除时设置为空
modelBuilder.Entity<Person>()
.HasOne(t => t.ReferredBy)
.WithOne()
.OnDelete(DeleteBehavior.SetNull);
现在,当我尝试插入具有相同ReferredByit的行时,将引发唯一约束错误。请帮助我。