This document provides an overview and agenda for Entity Framework (EF). It discusses key EF concepts like ORM, EF modeling using code first, database first, and model first approaches. It also covers EF features like LINQ, inheritance strategies, relationships, concurrency, and CRUD operations. Hands-on examples are provided for many topics.
3. Why Database Layer
Object Impedance Mismatch - RDBMS and OOP
Object Conversions - RDBMS to OOP and OOP to RDBMS
Needs Easy Conversion Process - Rise of ORM
4. ORM?
Many Frameworks - EF, NH, LINQ to SQL
RDBMS to NoSQL Support
Single RDBMS Support to Various RDBMS Support
DB Layer Uniformity Across the Organization
13. Modelling - Model First
Create model in EF Designer
Generate database from model
Classes auto-generated from model
Preferred approach for new database.
15. Modelling - Code First
Define classes and mapping in code
Database created from code
Migrations apply model changes to database
Preferred approach for new database. Generally
preferred in Agile/Scrum
16. Modelling - Fluent Api, Configuration and Conventions
Fluent Api - Chaining Api
Configuration with Fluent Api
Conventions
17. Hands On
Code First - Create Classes with Conventions only
Database Generation
Database Migration
36. EF - Inheritance Strategy - TPH
Needs a column, discriminator, that will used to identify exact type.
Retrieving Type in TPH
Code First Configuration
Gives better performance but there are many duplicate data and nullable columns.
38. EF - Inheritance Strategy - TPT
Each entity maps to table. So CUD operations are faster
Code First Configuration
Retrieval is slower than TPH as it needs joins with base class/table.
40. EF - Inheritance Strategy - TPC
Each concrete entity maps to table.
Code First Configuration
Properties of abstract entity are combined with concrete entity and many data/columns duplications.
EDMX designer does not support this mapping. Manual modification is required.
47. EF - Concurrency - Optimistic
None: Default and there is no concurrency
Fixed: Original value of concurrency column is included in where part while generating SQL
Rows are not locked. Read operation can be never locked