Entity Framework 4

1,449 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
1,449
On SlideShare
0
From Embeds
0
Number of Embeds
38
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Say word/two about each topic
  • What does ORM mapping do ?Custom classes as entity representing proxy do DBPOCO acronym non persistent classes
  • Unreadable code, bad programming style,bugish code.
  • No notice on using stored proc, security holes opened in application.
  • Unclear DDL logic
  • Programming speed.
  • DB easy switching, less time spent with multiplatform issues, less code.http://blogs.msdn.com/adonet/archive/2007/12/17/the-ado-net-entity-framework-not-just-for-sql-server.aspx
  • Less time getting nervous with debugging app-to-rdbm queries.
  • What can go wrong? Problem:Schema specified is not valid. Errors: The relationship ’DB’. 'Entity' was not loaded because the type 'DB’.’SecondEntity' is not available. Solution:Naming mistakes, check if class properties are same as in the Entity Model
  • Usually used when using web services.Definition of a new behavior attribute that will implement data serialization from proxy to known typeDataContractSerializer and ProxyDataContractResolverDataContractSerializer is instructed how so resolve proxy types.
  • Usually used when using web services.Definition of a new behavior attribute that will implement data serialization from proxy to known typeDataContractSerializer and ProxyDataContractResolverDataContractSerializer is instructed how so resolve proxy types.
  • Usually used when using web services.Definition of a new behavior attribute that will implement data serialization from proxy to known typeDataContractSerializer and ProxyDataContractResolverDataContractSerializer is instructed how so resolve proxy types.
  • Entity Framework 4

    1. 1. EF4 through POCO<br />11.02.2010<br />Marjan Nikolovski<br />
    2. 2. Agenda<br /> Page 2<br />Date: 11.02.2010<br />Author: Marjan Nikolovski<br /><ul><li>Introduction
    3. 3. Installation
    4. 4. Getting started
    5. 5. Loading entity properties
    6. 6. Tracking changes
    7. 7. Working with proxy enabled data
    8. 8. Serialization of proxy objects for WCF usage
    9. 9. Technology performance
    10. 10. Pros and Cons</li></li></ul><li>Introduction<br /> Page 3<br />Date: 11.02.2010<br /><ul><li>Yet Another ORM tool ?
    11. 11. Custom classes as data proxy
    12. 12. POCO acronym
    13. 13. Before and Now</li></ul>Author: Marjan Nikolovski<br />
    14. 14. Yet Another ORM tool ?<br />Date<br /> Page 4<br />Author<br /><ul><li>How it is different from the previous known
    15. 15. POCO vs. nHybernate, nHydrate, LINQ-SQL</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    16. 16. Date<br /> Page 5<br />Author<br />POCO acronym<br /><ul><li>Plain Old CLR Object
    17. 17. Acronym for non-persistant data (persistant ignorant)</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    18. 18. Before<br />Date<br /> Page 6<br />Author<br /><ul><li>Unreadable code
    19. 19. Bad programming style
    20. 20. Almost no extensible designs
    21. 21. Lot of bugs
    22. 22. Knotted logic</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    23. 23. Date<br /> Page 7<br />Author<br />Before<br /><ul><li>Forgotten CRUD principles
    24. 24. Security issues</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    25. 25. Date<br /> Page 8<br />Author<br />Before<br /><ul><li>Unclear DDL/BLL logic</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    26. 26. EF4 POCO now offers you:<br />Date<br /> Page 9<br />Author<br /><ul><li>Efficiency</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    27. 27. Date<br /> Page 10<br />Author<br />EF4 POCO now offers you:<br /><ul><li>Easy DB switching</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    28. 28. Date<br /> Page 11<br />Author<br />EF4 POCO now offers you:<br /><ul><li>Less time getting nervous with debuggingqueries.</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    29. 29. Installation<br />Date<br /> Page 12<br />Author<br /><ul><li>Visual Studio 2010 beta 2
    30. 30. ADO.NET Entity Framework Feature Community Technology Preview 2</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    31. 31. Getting started<br />Date<br /> Page 13<br />Author<br /><ul><li>Mapping requirements
    32. 32. DB mapping and POCO class generation
    33. 33. POCO code generator
    34. 34. Classes handcrafting
    35. 35. Data model to physical model</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    36. 36. Date<br /> Page 14<br />Author<br />Mapping requirementsGetting started<br /><ul><li>Custom data class must not be non inheritable, abstract or private
    37. 37. Custom data class must have a public parameter less constructor
    38. 38. For lazy loading custom data class navigational properties must be defined as overrideable (virtual).
    39. 39. Classes must not have any mapping attributes and must not implement IEntityWithChangeTrackeror IEntityWithRelationships interfaces.
    40. 40. ProxyCreationEnabled in the ObjectContext’sContextOptions must be set to true (default is true) for ObjectContext tracking.</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    41. 41. Date<br /> Page 15<br />Author<br />Mapping requirementsDB mapping and POCO class generation<br /><ul><li>Add Entity Model
    42. 42. Mapping DB to Model</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    43. 43. Date<br /> Page 16<br />Author<br />Mapping requirementsDB mapping and POCO class generation<br />Remove custom tool<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    44. 44. Date<br /> Page 17<br />Author<br />Mapping requirementsDB mapping and POCO class generationClasses handcrafting<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    45. 45. Date<br /> Page 18<br />Author<br />Mapping requirementsDB mapping and POCO class generationClasses handcrafting<br />Create DB Context<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    46. 46. Date<br /> Page 19<br />Author<br />Mapping requirementsDB mapping and POCO class generationClasses handcrafting<br />In practice<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    47. 47. Date<br /> Page 20<br />Author<br />Mapping requirementsData model to physical model<br /><ul><li>Same protocol used descripted above only bottom up strategy used
    48. 48. Create sql script </li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    49. 49. Loading entity navigational properties<br />Date<br /> Page 21<br />Author<br /><ul><li>Navigational properties
    50. 50. Explicit loading
    51. 51. Lazy loading
    52. 52. Eager loading</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    53. 53. Loading entity navigational propertiesExplicit loading<br />Date<br /> Page 22<br />Author<br />Lazy loading property in Object Context class must be set to false<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    54. 54. Loading entity navigational propertiesLazy loading <br />Date<br /> Page 23<br />Author<br />Lazy loading property in Object Context class must be set to true<br />in order set auto navigation data loading<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    55. 55. Loading entity navigational propertiesEager loading<br />Date<br /> Page 24<br />Author<br />Eager loading is done by calling include method in LINQ query<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    56. 56. Tracking changes<br />Date<br /> Page 25<br />Author<br /><ul><li>Proxy enabled mapping
    57. 57. Sharpshooting (self organized tracking)</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    58. 58. Tracking changesProxy enabled mapping<br />Date<br /> Page 26<br />Author<br /><ul><li>Automatic tracking of changes in the Context</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    59. 59. Tracking changesSharpshooting (self organized tracking)<br />Date<br /> Page 27<br />Author<br /><ul><li>Manual tracking of changes in the Context</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    60. 60. Working with proxy enabled data<br />Date<br /> Page 28<br />Author<br /><ul><li>Enabling proxy enabled mapping and data manipulation</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    61. 61. Working with proxy enabled dataEnabling proxy enabled mapping and data creation<br />Date<br /> Page 29<br />Author<br /><ul><li>ProxyCreationEnable property must be set to true
    62. 62. Creation of entity as proxy types</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    63. 63. Serialization of proxy objects for WCF usage<br />Date<br /> Page 30<br />Author<br /><ul><li>What has to be done ?
    64. 64. One side implementation</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    65. 65. Serialization of proxy objects for WCF usageWhat has to be done ?<br />Date<br /> Page 31<br />Author<br /><ul><li>Proxy object are objects of not known type
    66. 66. Defining service behavior where DataContractSerializer must be set in order proxy data to be resolved to known type</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    67. 67. Serialization of proxy objects for WCF usageOne side implementation<br />Date<br /> Page 32<br />Author<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    68. 68. Technology performance<br />Date<br /> Page 33<br />Author<br />Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    69. 69. Pros and Cons<br />Date<br /> Page 34<br />Author<br /><ul><li>Object simplicity and great extensibility
    70. 70. Speeding up DAL design and implementation
    71. 71. Manual context synchronization can be tricky when comes to business logic
    72. 72. Class construction overhead and memory overflow may occur when no proper handling is used</li></ul>Author: Marjan Nikolovski<br />Date: 11.02.2010<br />
    73. 73. Page 35<br />Date: 11.02.2010<br />Author: Marjan Nikolovski<br />Q&A<br />
    74. 74. Page 36<br />Date: 11.02.2010<br />Author: Marjan Nikolovski<br />References<br /><ul><li>http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-1-model-and-poco-classes/
    75. 75. http://www.code-magazine.com/Article.aspx?quickid=0909081
    76. 76. http://byatool.com/tag/entity-framework/
    77. 77. http://msdn.microsoft.com/en-us/magazine/ee236639.aspx
    78. 78. http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-self-tracking-entities-for-the-entity-framework.aspx
    79. 79. http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-poco-templates-for-the-entity-framework.aspx
    80. 80. http://blogs.msdn.com/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx
    81. 81. http://blogs.msdn.com/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx
    82. 82. http://blogs.msdn.com/adonet/archive/2009/05/19/sneak-peek-using-code-generation-templates-with-the-entity--framework-4-0.aspx
    83. 83. http://blogger.forgottenskies.com/?p=518
    84. 84. http://msdn.microsoft.com/en-us/magazine/ee335715.aspx
    85. 85. http://blogs.msdn.com/efdesign/</li></li></ul><li>

    ×