Entity Framework By Casey Griffin What is Entity
Entity Framework By: Casey Griffin
What is Entity Framework? • Object-Relational Mapper ▫ Object Programming / Database Programming ▫ Create Model (Code/EF Designer) • Part of the ADO. NET Stack – Between the applications and databases • Higher Level of Data Abstraction • Create/Maintain Data-Oriented Applications with Less Code
Conceptual Model • Entity Data Model – EDM /Domain Model • Represents Domain Objects/ Relationships between Entities • Reflects Application Logic • Higher Level of Abstraction
Development Workflows
Code First Approach • Since Entity Framework 4. 1 • Workflow ▫ Domain (POCO) Classes ▫ Db. Context API ▫ Code First Migrations
POCO Classes • Plain Old CLR Object Classes • Persistent Ignorance • Types of Properties: ▫ Scalar Properties ▫ Navigational Properties �Virtual Keyword (Lazy Loading)
Db. Context • • Lightweight version of the Object. Context Represent Database Session Querying and Saving Data Db. Set (Object. Set)– Query and Save Instances of Database Types
Code First Conventions • Conventions determine the database schema based on the domain model • Configuring/Overriding Conventions ▫ Data Annotations ▫ Fluent API
Data Annotations
Fluent API
Code First Migrations • • Enable Migrations Generating Seed Data Adding Migrations Updating the Database
The Griffin Drywall Project • The Website • Demo
Analysis • Comparison with Traditional Data Access ▫ Entity Framework Features ▫ Benefits and Disadvantages
Features • • Conceptual Layer –Multiple Backends Lazy Loading LINQ Querying Many to Many Relationships – Bridging Tables
Benefits and Disadvantages Benefits Disadvantages Bulk of 80 -90% of CRUD Functions 10 -20% SQL or Stored Procedures Rapid Development Speeds Not As Flexible as SQL/SP Maintainable Code Bad Generated SQL Isolated from Database
Conclusion • Entity Framework is easy to use and endows developers with higher level of abstraction which allows them to deal with the business logic rather than the database logic. • Future Projects ▫ Model First Approach ▫ EF vs Current ORMs
Questions • Open the presentation up for questions.
- Slides: 17