KEMBAR78
Architecting Smarter Apps with Entity Framework | PDF
Architecting
 Smarter Apps
 with Entity
 Framework




Julie Lerman
4/19/2011
Julie Lerman
    consultant/mentor
    Microsoft MVP, INETA Speaker,
    ASPInsider, MCP, VTdotNET Leader
    contact
    jlerman@theDataFarm.com
    www.thedatafarm.com
    blog
    theDataFarm.com/blog
    twitter
    @julielerman
    book web site
    LearnEntityFramework.com
EF4 Tools for
Persistence Ignorance




                        3
Persistence Ignorance via POCOs
                               Code First

Database First & Model First




                                            4
POCO
            Change Tracking “Snapshot”
                              4.0, 4.1

Person Object                            ObjectContext
                                                        State info
     Order Object                 State info

           Detail Object             State info
            Detail Object
                                                      State info
      Order Object
                                    State info
           Detail Object                          State info

            Detail Object
                                    State info
POCO Notes




             6
IObjectSet/IDbSet for Separation

• Set with Collection-like behavior
   – Add, Attach, Delete, etc.
• ObjectSet/DbSet
   – Concrete class
   – Implements IObjectSet/IDbSet
   – Inherits ObjectQuery
• Extensions to recreate EF specific methods
   – Include
PI/Repositories
                                   Classes
                                                     System.Data.Entity
  Fake
ObjectSet
                               Fake
                          Context & Data A             EDM &
            Fake
       Context & Data B                             ObjectContext


                                    Class
                                      Class
                                 Repositories
                                        Class
                                  Repositories
                                          Class
                                    Repositories
                                     Repositories           UI
     Tests
                                   Unit of Work
Summary

•   EF Defaults are great for quick drag & drop apps
•   EF can be used in testable, reusable architecture
•   Use POCOs to separate domain classes from data access
•   IObjectSet/IDbSet for building for agnostic repositories
•   Consider loss of framework specific features e.g., Include




                                                                 9
Resources

•   Book blog: learnentityframework.com
•   MSDN EF Dev Center: msdn.com/data/ef
•   EF Team Blog: blogs.msdn.com/adonet
•   Agile Entity Framework 4 Repository Blog Series
    – http://bit.ly/2VaFrr
• Testability and Entity Framework 4.0,
  Scott Allen, http://msdn.microsoft.com/en-us/ff714955.aspx


                                                               10

Architecting Smarter Apps with Entity Framework

  • 1.
    Architecting Smarter Apps with Entity Framework Julie Lerman 4/19/2011
  • 2.
    Julie Lerman consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leader contact jlerman@theDataFarm.com www.thedatafarm.com blog theDataFarm.com/blog twitter @julielerman book web site LearnEntityFramework.com
  • 3.
  • 4.
    Persistence Ignorance viaPOCOs Code First Database First & Model First 4
  • 5.
    POCO Change Tracking “Snapshot” 4.0, 4.1 Person Object ObjectContext State info Order Object State info Detail Object State info Detail Object State info Order Object State info Detail Object State info Detail Object State info
  • 6.
  • 7.
    IObjectSet/IDbSet for Separation •Set with Collection-like behavior – Add, Attach, Delete, etc. • ObjectSet/DbSet – Concrete class – Implements IObjectSet/IDbSet – Inherits ObjectQuery • Extensions to recreate EF specific methods – Include
  • 8.
    PI/Repositories Classes System.Data.Entity Fake ObjectSet Fake Context & Data A EDM & Fake Context & Data B ObjectContext Class Class Repositories Class Repositories Class Repositories Repositories UI Tests Unit of Work
  • 9.
    Summary • EF Defaults are great for quick drag & drop apps • EF can be used in testable, reusable architecture • Use POCOs to separate domain classes from data access • IObjectSet/IDbSet for building for agnostic repositories • Consider loss of framework specific features e.g., Include 9
  • 10.
    Resources • Book blog: learnentityframework.com • MSDN EF Dev Center: msdn.com/data/ef • EF Team Blog: blogs.msdn.com/adonet • Agile Entity Framework 4 Repository Blog Series – http://bit.ly/2VaFrr • Testability and Entity Framework 4.0, Scott Allen, http://msdn.microsoft.com/en-us/ff714955.aspx 10