An object-relational mapper (ORM) connects programming-language objects with relational database structures and operations. It lets an ASP.NET Core application work with database data through C# abstractions instead of writing every SQL query manually. section 4.0 section 4.3
An ORM is useful because it can:
- Reduce development time and the amount of data-access code. section 4.3.1
- Standardize retrieval strategies and reduce recurring implementation mistakes. section 4.3.1
- Expose features such as transactions, pooling, migrations, seeds, streams, and security measures. section 4.3.1
- Reduce manually assembled dynamic SQL and the associated SQL-injection risks. section 4.3.1
EF Core supplies the ORM layer. Its data model consists of C# classes representing database tables, while ApplicationDbContext provides the operational connection between ASP.NET Core and the database. Configure the context with a connection string, then use entities for CRUD operations and migrations to create the database structure from the model. section 4.5
Updating data through the ORM
Instead of constructing an UPDATE statement by interpolating a value into SQL, retrieve the user through DbContext, assign a new Notes value, and call SaveChanges(). The ORM presents the operation through C# while handling the database interaction. section 4.3.1
var user = DbContext.Users.Where(u => u.Id == 4); user.Notes = "this user has been disabled"; DbContext.SaveChanges();
Compare a C# entity update with the raw SQL and parameterized alternatives to see how the ORM changes the data-access abstraction. section 4.3.1






