Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is different between DeleteBehavior.NoAction and DeleteBehavior.Restrict in EntityFramework Core?

I have a configuration like this in my codes:

builder.HasMany(c => c.Libs)
       .WithOne(x=>x.Book)
       .HasForeignKey(x=>x.BookId)
       .OnDelete(DeleteBehavior.NoAction);  <<-------- Here

My question is what is different between NoAction and Restrict value?

I read Microsoft document and descriptions of both of them are same!!!

enter image description here

like image 633
Ramin Bateni Avatar asked Oct 08 '20 09:10

Ramin Bateni


People also ask

What is DeleteBehavior Cascade?

DeleteBehavior.Cascade – Delete the child when the parent is deleted (e.g. Cascading deletes) DeleteBehavior.SetNull – Set the FK on the child to just be null (So allow orphans) DeleteBehavior.Restrict – Don't allow the parent to be deleted at all.

What is WillCascadeOnDelete?

WillCascadeOnDelete(Boolean) Configures whether or not cascade delete is on for the relationship. C# Copy.


1 Answers

It depends on the database implementation.

In T-SQL and MySQL, there is no difference.

In PostgreSQL, there is a difference: Difference between RESTRICT and NO ACTION

like image 159
arni Avatar answered Oct 06 '22 02:10

arni