Skip to content Skip to sidebar Skip to footer

How To Remove Multiple Cascade Paths In Entity Framework

I am trying to define relationships between tables, but getting the following error: Introducing FOREIGN KEY constraint 'FK_QProducts_Quotes_QuoteId' on table 'QProducts' may caus

Solution 1:

Put simply, you cannot have cascade delete down to QProduct via multiple paths, which you do at the moment. You need to turn Cascade Delete off of one (or both, if you prefer).

For example, when configuring Product, try:

HasMany(p => p.QProducts)
   .WithOne(q => q.Product)
   .HasForeignKey(q => q.ProductId)
   .OnDelete(DeleteBehavior.Restrict);

You'll probably need to make the FK nullable also:

publicint? ProductId { get; set; }

Post a Comment for "How To Remove Multiple Cascade Paths In Entity Framework"