ENTITY FRAMEWORK – DELETE RECORDS FROM DATABASE WITH ENTITY FRAMEWORK | C# VISUAL STUDIO 2022



In this tutorial we are going to learn about delete records in c# visual studio 2022 using entity framework.
Deleting data via Entity framework in c# visual studio 2022
The approach that you adopt to deleting entities via the DbContext depends on whether the context is currently tracking the entity being deleted or not.

In the following example, the entity to be deleted is obtained by the context, so the context begins tracking it immediately. The DbContext.Remove method results in the entity’s EntityState being set to Deleted.
When SaveChanges is called, a DELETE statement is generated and executed by the database.

#csharp #tutorial #beginners #Deleteoperations #crudoperation #visualstudio2022

What is Entity Framework?
Prior to .NET 3.5, we (developers) often used to write ADO.NET code or Enterprise Data Access Block to save or retrieve application data from the underlying database. We used to open a connection to the database, create a DataSet to fetch or submit the data to the database, convert data from the DataSet to .NET objects or vice-versa to apply business rules. This was a cumbersome and error prone process. Microsoft has provided a framework called “Entity Framework” to automate all these database related activities for your application.

Entity Framework is an open-source ORM framework for .NET applications supported by Microsoft. It enables developers to work with data using objects of domain specific classes without focusing on the underlying database tables and columns where this data is stored. With the Entity Framework, developers can work at a higher level of abstraction when they deal with data, and can create and maintain data-oriented applications with less code compared with traditional applications.

Official Definition: “Entity Framework is an object-relational mapper (O/RM) that enables .NET developers to work with a database using .NET objects. It eliminates the need for most of the data-access code that developers usually need to write.”

The following figure illustrates where the Entity Framework fits into your application.

Follow my Facebook Page : https://www.facebook.com/105940115222549
Follow me on Instagram : https://www.instagram.com/p/CViUlw2sOMi
Follow me on tumblr : http://programming-guru.tumblr.com
Follow me on reddit : https://www.reddit.com/u/Programming_guru1?utm_medium=android_app&utm_source=share

Comments are closed.