Entity Framework 4 & WCF So Happy Together <br />Julie Lerman<br />www.thedatafarm.com<br />jlerman@thedatafarm.com<br />t...
Julie Lerman<br />website<br />theDataFarm.com<br />blog & twitter<br />theDataFarm.com/blog@julielermanVT<br />book web s...
Agenda<br />New Features in EF that help with n-Tier<br />POCO Support<br />Foreign Keys<br />State methods<br />Serializa...
EFv1 and N-Tier<br />EntityObjects are ugly when serialized<br />Transferring to & from DTOs is painful<br />No change-tra...
ObjectContext Manages Entities<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />ObjectContext<br />Per...
Hello POCO, Goodbye EntityObject<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
Code Gen POCOs from Model<br />T4<br />More in Kathleen Dollard’s 2:30 talk, Wednesday:<br />T4: Code Generation Microsoft...
New State Methods Support N-Tier<br />Fix up newly attached entity’s EntityState<br />ApplyCurrentValues<br />ApplyOrigina...
Context.ApplyCurrentValues<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />Server Entity<br /><ul><li...
EntityState=Unchanged</li></ul>Client side Entity<br /><ul><li>EntityState=Modified</li></ul>ApplyCurrentValues(Client Ent...
Foreign Key Support<br />Default with new models<br />Simplifies relationship management<br />Huge benefits from WCF clien...
Basic Pattern for WCF in EF4<br />Use POCO entity classes<br />No dynamic proxies (not virtual)<br />Include a State prope...
Self-Tracking Entities (! very agile)<br />For DataSet lovers<br />Special T4 Code Gen Template<br />Creates POCO Classes ...
Summary<br />WCF was painful in EF version 1<br />Many improvements in EF4 to help n-Tier<br />Writing custom WCF gets muc...
Julie Lerman<br />website<br />theDataFarm.com<br />blog & twitter<br />theDataFarm.com/blog@julielermanVT<br />book web s...
Upcoming SlideShare
Loading in …5
×

Entity Framework 4 and WCF

9,527 views

Published on

This presentation walks through the new features of Entity Framework in Visual Studio 2010 & .NET 4 that simplify using entities in WCF. The live session demo'd the features and a WCF service with a client consumer.

Published in: Technology, Education

Entity Framework 4 and WCF

  1. 1. Entity Framework 4 & WCF So Happy Together <br />Julie Lerman<br />www.thedatafarm.com<br />jlerman@thedatafarm.com<br />twitter @JulieLermanVT<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  2. 2. Julie Lerman<br />website<br />theDataFarm.com<br />blog & twitter<br />theDataFarm.com/blog@julielermanVT<br />book web site<br />LearnEntityFramework.com<br />consultant/mentor<br />Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />2nd Edition<br />Spring 2010<br />
  3. 3. Agenda<br />New Features in EF that help with n-Tier<br />POCO Support<br />Foreign Keys<br />State methods<br />Serialization improvement <br />Custom WCF Services<br />Self-Tracking Entities<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  4. 4. EFv1 and N-Tier<br />EntityObjects are ugly when serialized<br />Transferring to & from DTOs is painful<br />No change-tracking in the objects<br />Difficult & unsatisfying WCF patterns <br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  5. 5. ObjectContext Manages Entities<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />ObjectContext<br />Person Object<br />State info<br />State info<br />Order Object<br />State info<br />Detail Object<br />State info<br />Detail Object<br />State info<br />Order Object<br />State info<br />Detail Object<br />State info<br />Detail Object<br />
  6. 6. Hello POCO, Goodbye EntityObject<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  7. 7. Code Gen POCOs from Model<br />T4<br />More in Kathleen Dollard’s 2:30 talk, Wednesday:<br />T4: Code Generation Microsoft Style<br />Text Template Transformation Toolkit<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  8. 8. New State Methods Support N-Tier<br />Fix up newly attached entity’s EntityState<br />ApplyCurrentValues<br />ApplyOriginalValues<br />ChangeState<br />ChangeRelationshipState<br />Used when there are no foreign keys<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  9. 9. Context.ApplyCurrentValues<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />Server Entity<br /><ul><li>Managed by Context
  10. 10. EntityState=Unchanged</li></ul>Client side Entity<br /><ul><li>EntityState=Modified</li></ul>ApplyCurrentValues(Client Entity)<br />
  11. 11. Foreign Key Support<br />Default with new models<br />Simplifies relationship management<br />Huge benefits from WCF client to service<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  12. 12. Basic Pattern for WCF in EF4<br />Use POCO entity classes<br />No dynamic proxies (not virtual)<br />Include a State property in the classes<br />Return graphs<br />Attach returned data to new context<br />Fix up context state using POCO State<br />If not using FKs<br />Fix up relationships with help from DB data<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  13. 13. Self-Tracking Entities (! very agile)<br />For DataSet lovers<br />Special T4 Code Gen Template<br />Creates POCO Classes with state info<br />Creates additional classes & interfaces<br />“Magically: takes care of change tracking<br />Used in client (.NET 4.0) & service<br />For WCF/DataContract Serialization<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  14. 14. Summary<br />WCF was painful in EF version 1<br />Many improvements in EF4 to help n-Tier<br />Writing custom WCF gets much easier<br />Self-Tracking Entities are an out of the box solution to help DataSetdevs<br />Don’t forget about WCF Data Services and WCF RIA Services as well<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />
  15. 15. Julie Lerman<br />website<br />theDataFarm.com<br />blog & twitter<br />theDataFarm.com/blog@julielermanVT<br />book web site<br />LearnEntityFramework.com<br />consultant/mentor<br />Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />2nd Edition<br />Spring 2010<br />
  16. 16. Resources<br />Julie Lerman: Entity Framework 4 and WCF [ESDC March 2010]<br />

×