型号:
public class Candidate
{
public int PCountryId { get; set; }
public Country PCountry { get; set; }
public int NCountryId { get; set; }
public Country NCountry { get; set; }
}
错误:
Introducing FOREIGN KEY constraint 'FK_tblDetails_tblCountries_NCountryId' on table 'tblDetails' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint
尝试过
public int? NCountryId { get; set; }
[ForeignKey("NCountryId")]
public virtual Country NCountry { get; set; }
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
relationship.DeleteBehavior = DeleteBehavior.Restrict;
}