This document summarizes a presentation by Julie Lerman on agile development with Entity Framework 4. It introduces POCO classes that provide loose coupling and allow for better testing. It also discusses leveraging dynamic proxies for change tracking and lazy loading without requiring entity objects. The presentation covers code generation with T4 templates, model-first design, and code-only development where the model is inferred from classes.
2. Julie Lerman Julie Lerman: Agile Entity Framework 4 [ESDC March 2010] website theDataFarm.com blog & twitter theDataFarm.com/blog@julielermanVT book web site LearnEntityFramework.com consultant/mentor Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader 2nd Edition Spring 2010
3. Agenda Agile Entities POCO Classes Leveraging Proxies Customizable T4 Code Generation Persistence Ignorance Agile Modeling Model-First (Model-less) Code-Only Development Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
4. ObjectContext Manages Entities Julie Lerman: Agile Entity Framework 4 [ESDC March 2010] 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
5. Agile Entities in EF4 EF3.5 Requires EntityObject Provides automated entity management Entities bound to EF API EF4 Adds POCO Support Smarter ObjectContext Loose Coupling Persistence Ignorance Repositories & Unit Testing Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
6. POCO: Shifting the Responsibility Julie Lerman: Agile Entity Framework 4 [ESDC March 2010] ObjectSet “Snapshot” ObjectContext POCO Classes DynamicProxy (similar to EntityObject) “Proxy Notification”
7. Basic POCO Support Turn off code generation from EDMX “Convention” will auto-map classes/entities Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
8. POCO and Other EF Features Complex Types Use a class (no structs) to represent the type Explicit Loading ObjectContext.LoadProperty(myObj,”PropertyName”) ObjectContext.LoadProperty(myObj, o=>o.property) Lazy Loading (new to EF4) Virtual navigation properties get run-time proxy Two-Way Navigation Must be coded into classes Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
9. Dynamic Proxies Classes must be completely virtual Every single property Dynamic Proxy created at run time Provide features similar to EntityObject Change notification Relationship management Lazy Loading Lots of rules Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
10. Rules for Proxy Notification All properties must be virtual Use ICollection<T> for child collections ObjectContext.CreateObject<T> for new Class cannot be sealed Navigation properties cannot be sealed Class cannot be abstract Must have a constructor with no parameters Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
11. Code Gen POCOs from Model Julie Lerman: Agile Entity Framework 4 [ESDC March 2010] T4 More in Kathleen Dollard’s 2:30 talk, Wednesday: T4: Code Generation Microsoft Style Text Template Transformation Toolkit
12. Classes Persistence Ignorance/Repository System.Data.Entity Mock ObjectSet Mock Context A EDM & ObjectContext Mock Context B Class Repositories Class Repositories Class Repositories Class Repositories UI Tests Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
13. Agile Modeling in EF4 Julie Lerman: Agile Entity Framework 4 [ESDC March 2010] *Available in separate download: EF Feature CTP
14. Model First Define model Define entities, properties, property attributes Entity Keys, Identity Keys Field Type, Length, defaults. Relationships & their constraints (e.g. 1:*) Inheritance (TPT default) “Generate DB from Model” = Create DDL Run DDL against existing DB Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
15. Code-Only Design Part of the EF Feature CTP No model at all Metadata is inferred from classes Convention by Default EF will rely 100% on presumptions Configuration Follows Tweak configurations to modify behavior Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
16. Resources LearnEntityFramework.com/resources thedatafarm.com/blog/tags/ef4 blogs.msdn.com/adonet, efdesign, dsimmons, alexj, more... msdn.microsoft.com/data Gateway to whitepapers, forums, documentation Lots of bloggers on EF now! Google! Julie Lerman: Agile Entity Framework 4 [ESDC March 2010]
17. Contact Julie Lerman: Agile Entity Framework 4 [ESDC March 2010] website theDataFarm.com blog & twitter theDataFarm.com/blog@julielermanVT book web site LearnEntityFramework.com consultant/mentor Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader