New England Code Camp 14 presentation on architecting applications that use ADO.NET Entity Framework with repositories, persistence ignorant classes and unit testing.
2. Julie Lerman consultant/mentor Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader website theDataFarm.com blog & twitter theDataFarm.com/blog@julielerman book web site LearnEntityFramework.com 2nd Edition (EF4) is now available
4. “-ilities” Benefits: Extensibility Adaptability Testability Maintainability Quality Why should You Care? Persistence Ignorance (PI) Future-Proofing your investment Slide courtesy of Stephen Bohlen
5. Persistence Dependence Inherits from System.Data.Objects.ObjectContext var context = new PublishingEntities(); var book= (from b in context select books where bookid=3) .First(); b.Status = “Sent to Printer”; context.SaveChanges(); Entity Framework method Persistence Ignorance varbookMgr = new BookManager(); var book=bookMgr.GetBook(3); book.Status=“Sent to Printer”; bookMgr.Update(book); *your* class *your* method
8. ObjectContext Manages Entities POCO “Snapshot”4.0 POCO + Dynamic Runtime Proxy (4.0) EntityObject (3.5 & 4.0) ObjectContext Person Object State info State info Order Object State info Detail Object State info Detail Object State info Order Object State info Detail Object State info Detail Object
9. POCO Basics With or without code generation “Convention” will auto-map classes/entities
10. EF4 POCO Support All entity properties must be represented Hand Code Code Generation with T4 and T4 templates Snapshot ObjectContext does all of the work Lazy Loading Virtual navigation properties Dynamic Runtime Proxies Mark all entity (model) properties as virtual Proxy emulates EntityObject behavior
11. IObjectSet Abstraction IObjectSet Collection-like behavior Add, Attach, Delete, etc. ObjectSet Concrete class Implements IObjectSet Inherits ObjectQuery public class ObjectSet:ObjectQuery,IObjectSet
12. Classes PI/Repositories System.Data.Entity Fake ObjectSet Fake Context & Data A EDM & ObjectContext Fake Context & Data B Unit of Work Class Repositories Class Repositories Class Repositories Class Repositories UI Tests
13. Entity Framework 4 Supports POCO Separation of concerns Unit Testing Coming soon: Code First, currently in CTP4, not released
14. Resources msdn.com/data Learnentityframework.com Testability and Entity Framework 4.0,Scott Allen, http://msdn.microsoft.com/en-us/ff714955.aspx Agile Entity Framework 4 Repository: blog series http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-1-model-and-poco-classes/
15. Julie Lerman consultant/mentor Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader website theDataFarm.com blog & twitter theDataFarm.com/blog@julielerman book web site LearnEntityFramework.com 2nd Edition (EF4) is now available
16. Your Feedback is Important Please fill out a session evaluation form drop it off at the conference registration desk. Thank you!