dev-resources.site
for different kinds of informations.
Delete in EF 8 !
Published at
9/4/2023
Categories
csharp
entityframework
ef
dotnet
Author
bugandfix
Main Article
Author
9 person written this
bugandfix
open
Deleting a record efficiently using Entity Framework (EF) involves a few key considerations to minimize unnecessary database operations and improve performance.
public async void DeleteStudent(int Id)
{
UniverSityDBContext db = new UniverSityDBContext();
var studentData = db.Students.FindAsync(Id).Result;
if (studentData == null)
throw new Exception("Student not found");
db.Students.Remove(studentData);
await db.SaveChangesAsync();
}
//
public void DeleteStudentOptimized(int Id)
{
UniverSityDBContext db = new UniverSityDBContext();
var student = new Student { ID = Id };
var studentEntity = db.Students.Attach(student);
studentEntity.State = EntityState.Deleted;
db.SaveChanges();
}
entityframework Article's
30 articles in total
Entity Framework Core Code First
read article
Code First Approach with Entity Framework.
read article
Custom NET8 Entity Framework Core Generic Repository
read article
Link Many To Many entities with shadow join-table using Entity Framework Core
read article
Running Entity Framework Core Migrations with Optimizely CMS 12
read article
Check Pagination in .NET: With and Without Entity Framework
read article
EF Core 6 - correct types halving the execution time!
read article
EF Core 6 - This SqlTransaction has completed; it is no longer usable.
read article
Entity Framework Core Tutorial:Introduction to Entity Framework Core
read article
ReadOnly DbContext with Entity Framework
read article
[KOSD] Multiple Parallel Operations in Entity Framework Core (.NET 8)
read article
Entity Framework in .net core 6.0 - Code first and Database first approach
read article
5 EF Core Features You Need To Know
read article
C# | Best Practices for Pagination using EF Core 8
read article
C# | Using Entity Framework with PostgreSQL Database
read article
C# | Entity Framework Generic Repository with SOLID Design Pattern
read article
C# | Entity Framework Issues and Troubleshooting
read article
Entity Framework Core with Scalar Functions
read article
Prefer Empty Objects over Compiler tricks
read article
The Differences Between EntityFramework .Add and .AddAsync
read article
Entity FrameWork
read article
Load Appointments on Demand in Blazor Scheduler using Entity Framework Core
read article
Finding the Right Balance: Clean Architecture and Entity Framework in Practice
read article
Compilation steps in EF Core
read article
Learning is another full-time job.
read article
How To Use EF Core Interceptors
read article
Using Entity Framework Core 8 Owned Types HasData()
read article
Simple Event-Sourcing with EF Core and SQL Server
read article
Delete in EF 8 !
currently reading
Optimizing Database Access with Entity Framework - Lazy Loading vs. Eager Loading
read article
Featured ones: