• Like
Entity Framework Migration
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Entity Framework Migration

  • 1,732 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,732
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
7
Comments
0
Likes
0

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
  • Projecting: L2S can project to a structure. EF can't (run time exception) (see http://www.thedatafarm.com/blog/2008/08/15/AFewThingsYouCantDoWithEFQueriesWhichYouWontFindOutUntilRuntime.aspx)
  • Both frameworks have similar implementations for selecting collections of objects from stored procsFor POCO Objects – L2S can fetch using ExecuteCommand and will map the fields from the return type to the object type supplied. Missing or additional columns are ignored. EF doesn’t support POCO with V1.Multiple Results – L2S can handle multiple results but they must be coded manually. EF doesn’t have support for multiple results, but see the EFEXtensions library for a solution. Also see http://blogs.msdn.com/meek/archive/2008/03/26/ado-entity-framework-stored-procedure-customization.aspx. Scalar results – L2S can auto-map. EF requires manual mapping.Executing without results – L2S uses ExecuteCommand, EF requires creating ADO code as extension method of the context using ExecuteNonQuery
  • EF:Final projection must be an entity type that has the correct association and it can’t be modified along the way (Group By) see http://wildermuth.com/2008/12/28/Caution_when_Eager_Loading_in_the_Entity_Framework

Transcript

  • 1. Moving from LINQ to SQL to EF
    Jim Wooley
  • 2. Agenda
    Why migrate?
    Entity Shapes
    Query differences
    Context considerations
    Demo migration
  • 3. Migration Implications
    Migration not required
    If it ain’t broke, why fix it?
    Because it’s cool != cost justification
    Why Migrate?
    Increase maintainability
    Reduce complexity
    Add functionality
    Incremental migration encouraged
    Use it in new components
    Have tests to ensure refactoring
  • 4. Entity shapes
  • 5. Physical
    Entity mapping layers
    Conceptual
    Mapping
    Logical
    SSDL
    MSL
    CSDL
    Author
    Author
    Author
    Entity
    User
    Address
    Publisher
    Publisher
    Entity
    Publisher
  • 6. Many-to-Many
  • 7. Inheritance – Table per Heirarchy
  • 8. Inheritance-Table per Type
  • 9. Inheritance-Table per Class
  • 10. POCO Considerations
    L2S
    EF
    Collections inherit from Table<T>
    POCO Entities Supported through XML Mapping
    Collections from ObjectQuery<T>
    POCO Entities Inherit from EntityObject or ComplexObject
    IPOCO Support
    Coming with V4
    Post 4.0: Code First/Code Only
  • 11. Mapping options
  • 12. Migrating an Application
    Demo – Getting it to compile
  • 13. Query generation
    Dim q1 = FromcustInnwd.Customers _
             Wherecust.Country.StartsWith(“U")
    LINQ to SQL:WHERE Country LIKE @P0; @P0=“U%”
    EF 1.0:
    Where(CAST(CHARINDEX(N’U%’, Country) AS int)) = 1
    EF 4.0: WHERE Extent1.Country LIKE N’U%’
  • 14. Query differences
    L2S
    EF
    Use Contains to create IN clause
    Projecting to Structure
    First/Single
    No support for IN. Use multiple OR clauses in WHERE statement.
    (Fixed in 4.0)
  • 15. Dynamic Queries
    LINQ to SQL
    EF
    Use deferred execution and query compositionality
    Dynamically build Expression Trees
    IQueryable extended to take strings as predicates
    Use Entity SQL
  • 16. Stored Procedures to Select
    LINQ to SQL
    Entity Framework
    Select as Function
    Ctx.ExecuteCommand for POCO results
    Ctx.IMultipleResults
    Scalar results
    ExecuteCommand
    Select as Function
    No support for POCO
    No support for Multiple Results (see EFExtensions)
    Build extension method for scalar results
    Extension method using ExecuteNonQuery
  • 17. Stored Procedures to Update
    LINQ to SQL
    EF
    Use designer to map any/all stored procs
    Infers usage based on the InsertT, UpdateT, DeleteT functions
    Must map all 3 portions of CUD operation
  • 18. Dynamic Updates
    L2S
    EF
    Ctx.P.InsertOnSubmit
    Ctx.P.DeleteOnSubmit
    Child – Add/Remove
    InsertAllOnSubmit
    Ctx.AddObject
    Ctx.DeleteObject
    Ctx.AddToT,
    Ctx.DeleteFromT
    Child – Add/Remove
  • 19. Context Considerations
    Options
    Concurrency
    Transactions
    Exceptions
    Logging
  • 20. Eager Loading
    LINQ to SQL
    EF
    DataLoadOptions
    For grandchildren: include multiple LoadWith
    Can’t change options once set on context
    Can add filtering
    Parent.Include(“Child”)
    Parent.Include(“Child.GC”)
    Options set per query
    Filter in query
  • 21. Deferred (Lazy) Loading
    LINQ to SQL
    EF
    Enabled as long as the context remains in scope
    DeferredLoadingEnabled
    Explicitly call Child.Load
    CodeGallery sample for Lazy Loading.
    Lazy Loading by default in 4.0
  • 22. Migrating an Application
    Demo – Fixing the Bugs
  • 23. Important points
    Migration isn’t required
    Be prepared to justify cost
    Have regression baselines before refactoring
    Good architecture begets easier migrations
    Benchmark and check performance
    Check generated queries
  • 24. Resources
    http://blogs.msdn.com/adonet/
    http://blogs.msdn.com/efdesign/
    EF Migration whitepaper:http://msdn.microsoft.com/en-us/library/cc716791.aspx
    Forums: http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/threads/
    http://learnentityframework.com
  • 25. Jim Wooley
    www.ThinqLinq.com
    www.LinqInAction.net
    www.Twitter.com/LinqKinq
    Questions