Entity Framework NYC Firestarter

  • 3,940 views
Uploaded on

On Sept 27, 2010, Julie Lerman, Rachel Appel and Steve Bohlen presented a full day of Entity Framework presentations to help developers get started with EF. The presentations begin with "why entity …

On Sept 27, 2010, Julie Lerman, Rachel Appel and Steve Bohlen presented a full day of Entity Framework presentations to help developers get started with EF. The presentations begin with "why entity framework" and end with creating better architectures when using EF.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • plz open it for download
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
3,940
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
1
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. NYC
    Entity Framework
    Firestarter
  • 2. Speakers
  • 3. Entity Framework Firestarter
    Schedule
  • 4. Thanks Microsoft
    For Hosting and Lunch
  • 5. EF NYC Firestarter
    Part 1: It’s Time to Look at Entity Framework
    Julie Lerman
    thedatafarm.com/blog
    twitter @julielerman
  • 6. Julie Lerman
    website
    theDataFarm.com
    blog & twitter
    theDataFarm.com/blog@julielerman
    book web site
    LearnEntityFramework.com
    consultant/mentor
    Microsoft MVP, INETA Speaker,ASPInsider, MCP, VTdotNET Leader
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 7. Why Entity Framework?
    NYC Entity Framework Firestarter, Sept 27th 2010
    Object Relational Mapper
    ADO.NET
    Data
    Set
    ADO
    Record
    Set
    Entity
    Framework
    Object
    Spaces
  • 8. Design Time: EDMX
    EF Metadata vs Other ORMs
    NYC Entity Framework Firestarter, Sept 27th 2010
    DB
    DB
    EF Runtime Metadata (XML files)
    Conceptual Model
    Schema
    Database
    Structure
    Schema
    Designer Layout & Positioning
    Typical ORM
    Objects
  • 9. ADO.NET Today & Tomorrow
    NYC Entity Framework Firestarter, Sept 27th 2010
    DataSet
    Entity Framework
    LINQ to SQL
  • 10. Model in Entity Framework
    Model
    First
    Database
    First
    New
    Database
    Legacy
    Database
    Code
    First
    NYC Entity Framework Firestarter, Sept 27th 2010
    “M”
  • 11. Entity Framework
    Conceptual Model in your Apps
    UI
    DB
    Conceptual
    Model
    of your Domain
    App Logic
    Provider
    Query
    Track Changes
    Repository
    Updates to DB
    Business
    Objects
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 12. Time to Code
    A little modeling…
    A little querying…
    A little editing…
    A little saving…
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 13. FAQS
    Stored Procedure Support
    Use Views & Stored Procs – no table access
    Update the model when DB changes
    Mappings are highly customizable
    Inheritance
    Many to Many
    Merge tables
    Split tables
    etc
    Pass through queries & commands
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 14. Entity Framework Everywhere
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 15. Why Entity Framework Summary
    Microsoft’s in-the-box ORM
    Focus of Microsoft/.NET data access
    Use any back end db (with a provider)
    Use in any type of .NET application
    Backbone of many Microsoft technologies
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 16.  Part 2:What’s new in Entity Framework 4
    EF NYC Firestarter
    Steve Bohlen
    unhandled-exceptions.com/blog
    twitter @sbohlen
  • 17. Long Form: Comprehensive
    NYC Entity Framework Firestarter, Sept 27th 2010
    Model-first development
    Automatic pluralization
    Foreign keys in models
    POCO class support
    Lazy loading
    T4 Code Generation
    Template customization
    IObjectSet
    Virtual SaveChanges
    ObjectStateManagercontrol
    Self-tracking entities
    SQL generation improvements
    More LINQ operator support
    LINQ extensibility
    ExecuteStoreQuery
    ExecuteStoreCommand
    SPROC import improvements
    Model defined functions
    WPF designer integration
    Code-First development (Feature CTP)
  • 18. Short Form: Highlights
    Designer Improvements
    Foreign Keys
    New Code Generation
    Persistence Ignorance
    Change Tracking for WCF
    Better n-tier Support
    Lazy Loading
    Code-Only Development
  • 19. Designer Improvements
    Pluralization Support
    Generate Database from Model
    vs. only Reverse-Engineering in v1
    Improved SPROC Support
    SPROCs can return only entities in v1
    SPROCs can return strongly-typed projections in v4
  • 20. Foreign Key Support
    ERM vs exposed FKs (it’s a CHOICE via the dialog box)
    Does NOT replace the Nav properties
    DataContext is able to leverage this for some efficiencies
    Changing either the FK or the Nav property changes the other value (due to code-gen support)
  • 21. Code Generation
    Model  templates  Classes
    Code Generation Engine now T4 instead of proprietary engine in v1
    Tools support/syntax support resources
    review a quick look at the T4 syntax
    T4 Editor add-in
  • 22. (better) Persistence Ignorance
    EntityObject inheritance NOT required
    Snapshot-based
    No lazy loading support in this approach
    No Change Tracking
    must call ObjectContext.DetectChanges( )
    ObjectContext.Save( ) implicitly calls .DetectChanges( )
    Proxy-based
    virtual keyword is the ‘flag’ for this behavior
    virtual on all  change-tracking and lazy-load
    virtual on just navigation props  only lazy-loading
    Several Canned Templates
  • 23. WCF and Self-Tracking Entities
    T4 template for self-tracking entities
    Passing objects across serialization boundaries
  • 24. Lazy Loading
    v1 supported only explicit load of lazy collections
    ObjectContext.ContextOptions.LazyLoadingEnabled = true
    by default in NEW models, but NOT in imported v1 models
    Behavior scoped at the ObjectContext
    NOT at property level for entities
    Toggle-able before and after operations for query-specific granular lazy-loading behavior
  • 25. Explicit State Management
    ObjectContext.ApplyCurrentValues( )
    Formerly ApplyPropertyChanges( ) in v1
    ObjectContext.ApplyOriginalValues( )
    ObjectStateEntry.ChangeState( )
    Unchanged/Added/Modified/Deleted
    ObjectStateManager.ChangeRelationshipState( )
  • 26. Code-Only Support
    ‘Feature CTP’
    Classes  Entities
    Entities  Database (optionally)
    No Model Necessary
    Heavily Convention over Configuration
  • 27. Miscellaneous
    Model-Defined Functions
    ObjectSet (collections of entities)
    Complex Type Support
    Query optimization (E-SQL, LINQ2Entities)
    ExecuteCommand/Defined Queries/Model Functions
    Designer support for more features without direct editing of .csdl, .ssdl, .edml
  • 28.  Part 4: Getting Started with POCOs in EF4
    EF NYC Firestarter
    Julie Lerman
    thedatafarm.com/blog
    twitter @julielerman
  • 29. Agenda
    Simple POCO Classes
    Leveraging Proxies
    Customizable T4 Code Generation
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 30. POCO
    Plain Old CLR Objects
  • 31. Benefits
    Use existing classes
    Loose Coupling
    Classes have no dependency on EF
    Persistence Ignorance
    Unit Testing
    Repositories & Unit Of Work Patterns
  • 32. ObjectContext Manages Entities
    NYC Entity Framework Firestarter, Sept 27th 2010
    POCO
    “Snapshot”4.0
    EntityObject
    (3.5 & 4.0)
    ObjectContext
    Person Object
    State info
    State info
    Order Object
    State info
    Detail Object
    State info
    Detail Object
    State info
    Order Object
    State info
    Detail Object
    State info
    Detail Object
  • 33. POCO Support Basics
    Turn off code generation from EDMX
    “Convention” will auto-map classes/entities
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 34. POCO and Other EF Features
    Complex Types
    Use a class (no structs) to represent the type
    Explicit Loading
    ObjectContext.LoadProperty(myObj,”PropertyName”)
    ObjectContext.LoadProperty(myObj, o=>o.property)
    Two-Way Navigation
    Must be coded into classes
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 35. Lazy Loading POCOs
    virtual (Overridable) navigation properties
    IRelatedEnd wrapper at run-time
    LazyLoadingEnabled=true required
    Selectively allow lazy loaded properties
    publicList<CreditCard>CreditCards {get; set; }
    virtualpublicPersonPerson {get;set; }
    publicList<Order> Orders { get;set; }
  • 36. ObjectContext Manages Entities
    NYC Entity Framework Firestarter, Sept 27th 2010
    POCO
    “Snapshot”4.0
    POCO
    + Dynamic Runtime Proxy
    (4.0)
    EntityObject
    (3.5 & 4.0)
    ObjectContext
    Person Object
    State info
    State info
    Order Object
    State info
    Detail Object
    State info
    Detail Object
    State info
    Order Object
    State info
    Detail Object
    State info
    Detail Object
  • 37. Dynamic Runtime Proxy Classes
    Person
    class
    F5
    Mark all Entity (model) Properties virtual
    Provides features similar to EntityObject
    Change notification
    Relationship management
    Lazy Loading
  • 40. Rules for Proxy Notification
    All entity properties shall be virtual
    Though shalt use ICollection<T>
    Creation shall be done withObjectContext.CreateObject<T>
    Classes shall not be sealed
    Navigation properties shall not be sealed
    Classes shall not be abstract
    Classes shall have a parameter-less constructor
  • 41. Code Gen POCOs from Model
    T4
    T
    4
    Text Template Transformation Toolkit
  • 42. EF POCO Summary
    POCO support is new to EF4
    Alternative to EntityObjects
    Simple snapshot POCOs or use proxies
    Use or even customize T4 template for code generation
    Enable many coding/architectural possibilities
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 43.  Part 5: Disconnected Strategies for ASP.NET & Services
    EF NYC Firestarter
    Julie Lerman
    thedatafarm.com/blog
    twitter @julielerman
  • 44. Agenda
    EF Challenges in Server Aps
    Review Options with EF
    EF4 Tools to the Rescue
    POCOs and Repositories
    Leveraging Foreign Keys
    Putting it all together
  • 45. 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
  • 46. 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
  • 47. The Server Side Spectrum with EF
    Dynamic Data forEntities
    ObjectDataSource
    WCF &
    Self-Tracking Ents
    EntityDataSource
    MVC
    WCF
    Data
    Services
    Dev
    WCF
    ASP.NET
    n-Tier
    Architect
  • 48. 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
    Self-Tracking Entities for use with WCF
  • 49. What about?
    Graphs
    Lazy Loading
    Returning IQueryables
    Change
    Tracking
  • 50. NYC Entity Framework Firestarter, Sept 27th 2010
    Oh, goody….
    time for code…
  • 51. Disconnected Strategies Summary
    EF has inherent challenges across tiers
    New tools in EF4 to enable disconnected
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 52.  Part 6:Writing Testable/Maintainable Apps with EF
    EF NYC Firestarter
    Steve Bohlen
    unhandled-exceptions.com/blog
    twitter @sbohlen
    Julie Lerman
    thedatafarm.com/blog
    twitter @julielerman
  • 53. Agenda
    Setting the stage
    Refactor a demo-worthy MVC app
    Explore an existing solution with more complexity
  • 54. “-ilities”
    Benefits:
    Extensibility
    Adaptability
    Testability
    Maintainability
    Quality 
    Why should You Care?
    Persistence Ignorance (PI)
    Future-Proofing your investment
    NYC Entity Framework Firestarter, Sept 27th 2010
  • 55. IObjectSet Abstraction
    IObjectSet
    Collection-like behavior
    Add, Attach, Delete, etc.
    ObjectSet
    Concrete class
    Implements IObjectSet
    Inherits ObjectQuery
    public class ObjectSet:ObjectQuery,IObjectSet
  • 56. EF4 Goodness Makes This Work
    NYC Entity Framework Firestarter, Sept 27th 2010
    POCOs
    +
    T4 Code Gen
    Disconnected Methods
    IObjectSet
  • 57. Classes
    PI/Repositories
    System.Data.Entity
    Fake
    ObjectSet
    Fake
    Context & Data A
    EDM &
    ObjectContext
    Fake
    Context & Data B
    Unit of Work
    Class
    Repositories
    Class
    Repositories
    Class
    Repositories
    Repositories
    UI
    Tests
  • 58. Resources
    LearnEntityFramework.com/resources
    thedatafarm.com/blog/tags/ef4
    blogs.msdn.com/adonet, efdesign, dsimmons, alexj, more...
    msdn.microsoft.com/data
    Gateway to whitepapers, forums, documentation
    Lots of bloggers on EF now! Google! 
    -Bing!
    NYC Entity Framework Firestarter, Sept 27th 2010