W Entity Framework 7, gdy próbuję zastosować migracji pojawia się błądOkreślanie ON DELETE NO ACTION w Entity Framework 7?
Wprowadzenie ograniczenia klucz obcy „FK_ChangeOrder_User_CreatedByID” na stole „ChangeOrder” może powodować cykli lub wiele ścieżek kaskadowe. Określ ON DELETE NO ACTION lub ON UPDATE NO ACTION lub zmodyfikuj inne ograniczenia klucza OBCEGO.
Nie można utworzyć ograniczenia. Zobacz poprzednie błędy.
wiem w starszych wersjach Entity Framework byś sobie z tym poradzić, dodając
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
do DbContext ale w EF7 modelBuilder
nie wydaje się mieć .Conventions
do niego i google zwraca tylko starsze EF 4 mimo EF 6 wyników.
Jak konkretnie ograniczyć ograniczenie ON DELETE NO ACTION
w Entity Framework 7?
Edytuj: Odpowiedź udzielona przez Olega będzie widoczna dla każdego klucza obcego, ale chciałbym zrobić to globalnie, ponieważ znacznie łatwiej będzie użyć jednego wiersza kodu, aby zadeklarować to globalnie, a następnie określić kod dla każdy z setek relacji, które będę miał.
Edycja 2: Kod Oleg
public class ChangeOrder
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public Int16? ApprovedByID { get; set; }
public Byte ApprovalStatusID { get; set; }
public Int16 AssignedToID { get; set; }
public Int16 CreatedByID { get; set; }
public Byte CurrentStatusID { get; set; }
public DateTime? DateApproved { get; set; }
public DateTime? EndDate { get; set; }
public Byte ImpactID { get; set; }
public Byte PriorityID { get; set; }
public DateTime? StartDate { get; set; }
public Byte TypeID { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string ReasonForChange { get; set; }
[ForeignKey("ApprovedByID")]
public User ApprovedBy { get; set; }
[ForeignKey("ApprovalStatusID")]
public ChangeApprovalStatus ApprovalStatus { get; set; }
[ForeignKey("AssignedToID")]
public User AssignedTo { get; set; }
[ForeignKey("CreatedByID")]
public User CreatedBy { get; set; }
[ForeignKey("ImpactID")]
public ChangeImpact Impact { get; set; }
[ForeignKey("PriorityID")]
public ChangePriority Priority { get; set; }
[ForeignKey("TypeID")]
public ChangeType ChangeType { get; set; }
[ForeignKey("CurrentStatusID")]
public ChangeStatus CurrentStatus { get; set; }
}
public class JobSightDBContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelbuilder)
{
base.OnModelCreating(modelbuilder);
}
DbSet<ChangeApprovalStatus> ChangeApprovalStatus { get; set; }
DbSet<ChangeImpact> ChangeImapct { get; set; }
DbSet<ChangeOrder> ChangeOrders { get; set; }
DbSet<ChangePriority> ChangePriorities { get; set; }
DbSet<ChangeStatus> ChangeStatus { get; set; }
DbSet<ChangeType> ChangeTypes { get; set; }
DbSet<User> Users { get; set; }
}
to uratowało mi życie !!!!! Otrzymywałem wiele modelujących problemów FK. Stukrotne dzięki!!!!!!!!!!!!!! –