Do You Know The Fastest Way To Delete Data With EF Core?

preview_player
Показать описание

What is the fastest way to delete data with EF Core? The standard approach requires two database requests, but I'll show you two options that only need one. The first uses the Attach method, and the second uses ExecuteDelete (released in EF Core 7).

Join my weekly .NET newsletter:

Read my Blog here:

Subscribe for more:

Chapters
0:00 Approach 1: Load from DB and Remove
4:08 Approach 2: Attach and Remove
7:12 Problem with Attach approach
8:00 Approach 3: ExecuteDelete (EF 7+)
Рекомендации по теме
Комментарии
Автор

Thanks Milan, your Step by step approch of explaination really improves thoughts process ❤

arjundate
Автор

Awesome content. Keep up the good work. Thank you very much.

JosephRuhundwa
Автор

Hi M. Your videos are great, I ve been using them while learning Blazor. Regards

tonym
Автор

Thanks for the video Milan, I only knew the first approach for deleting with EF, this helped me use better code.
Also, will you be making a video showing alternatives for smaller projects instead of clean architecture which is more used for bigger projects?

Arthuthu
Автор

Now i know what approch i will take. Thank Milan.

kodindoyannick
Автор

Thanks for the video Milan but i was just wondering why you didn't include the raw sql query as a 4th option. Best regards! Keep on helping us!

niangel
Автор

Useful and clear as usual, indeed I started to use the 3th approach since it's release, thanks Milan,
what do you think if someone using soft delete and only change a property flag on the SaveChanges call, this may avoid the exception in the second approach.. right?

mohamed-hassan-
Автор

For the 2nd approach no need to attach that entity and change it's state. You can just set the correct id and pass it to the Remove function.

Fikusiklol
Автор

As ExecuteDeleteAsync is only available in .NET 7 so, we will be using the first method ?

shahzadbashir
Автор

Do you have any getting started guides with EF?

rosenpetrov
Автор

Nice video, just curious why we would need savechanges approach if we can delete it with 3rd approach alone? Is there any scenario where we may need to call savechanges along with 3rd approach?

microtech
Автор

How do you get the inline values during debugging?

kewqie
Автор

Nice! So Products.Attach() will recognize the record by the id even if it's the only property with a value? It won't cause issues because all the other properties are null?

milos
Автор

what if we create a new object of product model with only Id property and then pass this object to Remove() Method

amirdar
Автор

Is it possible to code in MacOS for .NET?

GustavoDiaz
Автор

Unfortunately, there is a bug associated with owned entity types. I could not figure out a solution to use ExecuteUpdate and ExecuteDelete with entities which contain value objects inside :/

ArkunderTV
Автор

❤brilliant
Save changes not required?

arunbm
Автор

you can show us how to update child with ef? 2 or 3 level child i don't find a good material about that

dionismendanha
Автор

I'm having a tough time simply trying to delete a regular one to many relationship and it's really frustrating me.

I've got a User model that has a location ID which links to one location, but one location can belong on many users. However any attempt to delete it never actually deletes it and I cannot fathom why

thebulletkin
Автор

Year 2014, NHibernate delete new product() { Id = 1 } was possible, without bloated attach and other code. Simpler, less coupling to orm...

balazs.hideghety