Orm 3
Orm 3
(ORM)
Lecture 01
Introduction
● What is ORM: ORM is a programming technique that facilitates the
conversion of data between incompatible type systems in object-
oriented programming languages and relational databases.
● Purpose: It aims to bridge the gap between the object-oriented
programming paradigm and the relational database model, allowing
developers to work with database data in an object-oriented manner.
● ORM Frameworks: Examples include Hibernate for Java, Entity
Framework for .NET, SQLAlchemy for Python, and Doctrine for PHP.
Components of ORM
● Domain Class Objects: These are the object-oriented representations of
entities within the application's domain. For instance, in a library application,
classes like Book, Author, and Library could be domain class objects.
● Relational Database Objects: These are the tables, rows, and columns in a
relational database that store the data. Each domain class object typically
corresponds to a table in the database.
● Mapping Information: ORM frameworks use mapping information to
establish the relationships between domain class objects and relational
database objects. This mapping defines how data is persisted and retrieved.
Introduction to Entity Framework (EF)
● Entity Framework (EF): EF is an ORM framework developed by
Microsoft for .NET applications. It enables developers to work with
data in the form of domain class objects rather than writing complex
SQL queries.
● Integration with .NET: EF seamlessly integrates with the .NET
ecosystem, providing a set of tools and libraries for database
interactions.
● Advantages: Simplifies data access, reduces boilerplate code,
supports multiple database providers (SQL Server, MySQL, SQLite,
etc.).
Layers in Application
Architecture
● Presentation Layer: This layer handles user interactions and
displays information to the user. It includes components like UI
controls, views, and controllers.
● Business Logic Layer: Contains the business rules and logic of the
application. It orchestrates data processing and interacts with the
data access layer.
● Data Access Layer (DAL): EF resides in this layer, abstracting the
interaction with the database. It provides functionalities for querying,
inserting, updating, and deleting data without directly manipulating
SQL.
Where Entity Framework Fits ?
Entity Framework Main Classes
● DbContext Class (represents database): The DbContext class is the
entry point for using EF. It represents a session with the database and
provides APIs for querying and saving data. It also used to configure
domain classes, database related mappings, change tracking settings,
transactions etc.
● Entity (represents tables): An entity is a class that represents a
database table or view. Each instance of an entity class corresponds to a
row in the table, and its properties map to columns. Use to represent an
entity set that is used for create, read, update and delete operations.
Entity Framework Components
Properties of Entity class: Properties of an entity class define the
attributes of the corresponding database table's columns.
}
2. Dynamic Proxy (POCO Proxy) Entity
● Dynamic proxy entities are runtime-generated subclasses of POCO
entities, created by Entity Framework to enable lazy loading,
change tracking, and proxy-based behavior.
● Characteristics:
● Dynamic proxy entities are created when lazy loading or
change tracking is enabled in Entity Framework.
● They inherit from the original POCO entity class and override
virtual properties to add behavior.
● Dynamic proxy entities enable features like lazy loading of
navigation properties and change tracking without modifying
the original entity class.
Dynamic proxy entity class (generated by Entity Framework):
}
ProxyCreationEnabled Option
● Programming Entity Framework: Building Data Centric Apps with the ADO.NET Entity
Framework by Julia Lerman