2. Julie Lerman website theDataFarm.com blog & twitter theDataFarm.com/blog@julielermanVT book web site LearnEntityFramework.com consultant/mentor Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader
3. Agenda New Features in EF that help with n-tier POCO Support Foreign Keys State methods Serialization improvement Custom WCF Services Self-Tracking Entities
4. EFv1 and N-Tier EntityObjects are ugly when serialized Transferring to & from DTOs is painful No change-tracking in the objects Difficult & unsatisfying WCF patterns
5. Basic POCO Support in EF4 Turn off code generation from EDMX “Convention” will auto-map classes/entities
6. Additional POCO Features Change Tracking By Snapshot or Proxy Lazy Loading By Proxy Code Only Design No Physical Model Convention and Configuration
7. Simpler Code Gen Customization T4 Text Template Transformation Toolkit
8. New State Methods Support N-Tier ApplyCurrentValues ApplyOriginalValues ChangeState ChangeRelationshipState Used when there are no foreign keys
9. Change State w ApplyCurrentValues Client Requests Object Service queries db/cache &returns object fName: Julie lName: Lerman Client User Edits Object & returns to service fName: Julie lName: Flynn Service queries db/cache for original object fName: Julie fName: Julie lName: Lerman Service updates original object with values from client lName: Flynn SaveChanges ApplyCurrentValues
10. Foreign Key Support Arrived in Beta 2 Default with new models Simplifies relationship management
11. Basic Pattern for WCF in EF4 Use POCO entity classes Include a State property in the classes Return graphs Attach returned data to new context Fix up context state using POCO state If not using FKs Fix up relationships with help from db data
12. Self-Tracking Entities Special API in Feature CTP POCO Classes with state information Special method to apply changes to an entire graph Magically takes care of change tracking Written for WCF and DataContract Serialization Does not apply to ASP.NET, etc.
13. Summary WCF was painful in EF version 1 Many improvements in EF4 to help n-Tier Writing custom WCF gets much easier Self-Tracking Entities are a good out of the box solution Don’t forget about ADO.NET Data Services and RIA Services as well
14. Julie Lerman website theDataFarm.com blog & twitter theDataFarm.com/blog@julielermanVT book web site LearnEntityFramework.com consultant/mentor Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader
15. Resources EF Team Blogs (blogs.msdn.com/) adonet, efdesign, dsimmons, adjames, more.. Rowan Miller (romiller.com) (EF Team) WCF EF POCO demo with unit tests Danny Simmons’ Aug 2009 MSDN Mag MS PAG: Data Access Guidance dataguidance.codeplex.com