This document discusses how to architect smarter applications using Entity Framework. It recommends using POCOs to separate domain classes from data access for testability and reusability. It also suggests implementing IObjectSet/IDbSet interfaces to build agnostic repositories. This allows preserving testability while still using Entity Framework functionality like change tracking through interfaces. The document concludes that while EF defaults allow quick development, it can also support reusable architectures with testable classes and repositories when using POCOs and interfaces.
2. Julie Lerman
consultant/mentor
Microsoft MVP, INETA Speaker,
ASPInsider, MCP, VTdotNET Leader
contact
jlerman@theDataFarm.com
www.thedatafarm.com
blog
theDataFarm.com/blog
twitter
@julielerman
book web site
LearnEntityFramework.com
5. POCO
Change Tracking “Snapshot”
4.0, 4.1
Person Object ObjectContext
State info
Order Object State info
Detail Object State info
Detail Object
State info
Order Object
State info
Detail Object State info
Detail Object
State info
7. IObjectSet/IDbSet for Separation
• Set with Collection-like behavior
– Add, Attach, Delete, etc.
• ObjectSet/DbSet
– Concrete class
– Implements IObjectSet/IDbSet
– Inherits ObjectQuery
• Extensions to recreate EF specific methods
– Include
8. PI/Repositories
Classes
System.Data.Entity
Fake
ObjectSet
Fake
Context & Data A EDM &
Fake
Context & Data B ObjectContext
Class
Class
Repositories
Class
Repositories
Class
Repositories
Repositories UI
Tests
Unit of Work
9. Summary
• EF Defaults are great for quick drag & drop apps
• EF can be used in testable, reusable architecture
• Use POCOs to separate domain classes from data access
• IObjectSet/IDbSet for building for agnostic repositories
• Consider loss of framework specific features e.g., Include
9
10. Resources
• Book blog: learnentityframework.com
• MSDN EF Dev Center: msdn.com/data/ef
• EF Team Blog: blogs.msdn.com/adonet
• Agile Entity Framework 4 Repository Blog Series
– http://bit.ly/2VaFrr
• Testability and Entity Framework 4.0,
Scott Allen, http://msdn.microsoft.com/en-us/ff714955.aspx
10