Getting Persistence Ignorant with Entity Framework, Julie Lerman

3,965 views

Published on

New England Code Camp 14 presentation on architecting applications that use ADO.NET Entity Framework with repositories, persistence ignorant classes and unit testing.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,965
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Getting Persistence Ignorant with Entity Framework, Julie Lerman

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

×