New England Code Camp 14 presentation on tips & tricks for using new features in EF4 when building WebForms applications with Entity Framework. by Julie Lerman.
Building n-Tier ASP.NET WebForms with Entity Framework 4, Lerman
1. Building n-Tier ASP.NET Web Forms with Entity Framework Julie Lermanthedatafarm.com jlerman@thedatafarm.com Twitter @julielerman
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
3. Agenda EF Challenges in Web Apps Review WebForm Options with EF EF4 Tools to the Rescue POCOs and Repositories Leveraging Foreign Keys Putting it all together
4. The ASP.net Spectrum with EF Dynamic Data forEntities ObjectDataSource EntityDataSource MVC ADO.NET Data Services Dev WCF n-Tier Architect
5. Change Tracking Across Tiers ObjectContext ObjectStateEntry SO1 EntityKey Original ValuesCurrent Values Other ∆ Info ObjectStateEntry SO2 EntityKeyOriginal ValuesCurrent ValuesOther ∆ Info detach entities ObjectStateEntry LIA EntityKeyOriginal ValuesCurrent ValuesOther ∆ Info Original Property Values EntityState Values ObjectStateEntry LIB EntityKeyOriginal ValuesCurrent ValuesOther ∆ Info
6. SaveChanges Fails Across Post Backs Page Request Post Back #1 Post Back #2 New Page Class New Page Class New Page Class Create New ObjectContext Create NewObjectContext Create NewObjectContext Get Entities Process Request Get Entities Build HTML using Data & ASP.NET Markup Build HTML using Data & ASP.NET Markup Build HTML using Data & ASP.NET Markup Destroy Page and Dependents Destroy Page and Dependents Destroy Page and Dependents
7. EF4 Changes to the Rescue Foreign Keys Big help for selected list values on postback State Methods ApplyCurrentValues, ApplyOriginalValues ChangeState ChangeRelationshipState (when no FKs) POCO Classes & T4 Generation
11. Basic Pattern for ASP.NET n-Tier Code Behind Business Logic Repository Transient ObjectContext, Queries CacheEntityKeys, Scalars (inc FKs) Foreign Keys make this approach a possibility Entity Framework
12. 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
13. Your Feedback is Important Please fill out a session evaluation form drop it off at the conference registration desk. Thank you!
Editor's Notes
Abtract: Creating n-tier applications with Entity Framework got a whole lot easier in .NET 4.0. But if you are using ASP.NET Web Forms, there are still some tricks that you’ll need to know, especially if you are not a fan of using the binding sources, such as EntityDataSource and ObjectDataSource. In this session, you’ll see how to create a bridge between your Web Forms and a repository which serves up Entity Framework entities. You’ll lean some of the tools you’ll need to handle related datasuch as master-detail and foreign key