entity framework 4

Post on 11-May-2015

1.147 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

www.seavus.com

EF4 through POCO

11.02.2010

Marjan Nikolovski

Agenda

Page 2Date: 11.02.2010Author: Marjan Nikolovski

• Introduction• Installation• Getting started• Loading entity properties• Tracking changes• Working with proxy enabled data• Serialization of proxy objects for WCF usage• Technology performance• Pros and Cons

Introduction

Page 3Date: 11.02.2010Author: Marjan Nikolovski

• Yet Another ORM tool ?• Custom classes as data proxy• POCO acronym• Before and Now

Yet Another ORM tool ?

Date Page 4Author

• How it is different from the previous known• POCO vs. nHybernate, nHydrate, LINQ-SQL

Date: 11.02.2010Author: Marjan Nikolovski

POCO nHybernate

nHydrate LINK-SQL

portable

easy extensible

visual mapper

mature

Support LINQ

Date Page 5Author

POCO acronym

• Plain Old CLR Object• Acronym for non-persistant data (persistant ignorant)

Date: 11.02.2010Author: Marjan Nikolovski

Before

Date Page 6Author

• Unreadable code• Bad programming style• Almost no extensible designs• Lot of bugs• Knotted logic

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 7Author

• Forgotten CRUD principles• Security issues

Date: 11.02.2010Author: Marjan Nikolovski

Before

Date Page 8Author

• Unclear DDL/BLL logic

Date: 11.02.2010Author: Marjan Nikolovski

Before

EF4 POCO now offers you:

Date Page 9Author

• Efficiency

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 10Author

• Easy DB switching

Date: 11.02.2010Author: Marjan Nikolovski

EF4 POCO now offers you:

Date Page 11Author

• Less time getting nervous with debugging queries.

Date: 11.02.2010Author: Marjan Nikolovski

EF4 POCO now offers you:

Installation

Date Page 12Author

• Visual Studio 2010 beta 2• ADO.NET Entity Framework Feature Community

Technology Preview 2

Date: 11.02.2010Author: Marjan Nikolovski

Getting started

Date Page 13Author

• Mapping requirements• DB mapping and POCO class generation• POCO code generator• Classes handcrafting

• Data model to physical model

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 14Author

Mapping requirementsGetting started

• Custom data class must not be non inheritable, abstract or private • Custom data class must have a public parameter less constructor • For lazy loading custom data class navigational properties must be

defined as overrideable (virtual).• Classes must not have any mapping attributes and must not

implement IEntityWithChangeTracker or IEntityWithRelationships interfaces.

• ProxyCreationEnabled in the ObjectContext’s ContextOptions must be set to true (default is true) for ObjectContext tracking.

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 15Author

Mapping requirementsDB mapping and POCO class generation• Add Entity Model• Mapping DB to Model

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 16Author

Mapping requirementsDB mapping and POCO class generationRemove custom tool

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 17Author

Mapping requirementsDB mapping and POCO class generationClasses handcrafting

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 18Author

Mapping requirementsDB mapping and POCO class generationClasses handcraftingCreate DB Context

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 19Author

Mapping requirementsDB mapping and POCO class generationClasses handcraftingIn practice

Date: 11.02.2010Author: Marjan Nikolovski

Date Page 20Author

Mapping requirementsData model to physical model• Same protocol used descripted above only bottom

up strategy used• Create sql script

Date: 11.02.2010Author: Marjan Nikolovski

Loading entity navigational properties

Date Page 21Author

• Navigational properties• Explicit loading• Lazy loading• Eager loading

Date: 11.02.2010Author: Marjan Nikolovski

Loading entity navigational propertiesExplicit loading

Date Page 22Author

Date: 11.02.2010Author: Marjan Nikolovski

Lazy loading property in Object Context class must be set to false

Loading entity navigational propertiesLazy loading

Date Page 23Author

Date: 11.02.2010Author: Marjan Nikolovski

Lazy loading property in Object Context class must be set to truein order set auto navigation data loading

Loading entity navigational propertiesEager loading

Date Page 24Author

Date: 11.02.2010Author: Marjan Nikolovski

Eager loading is done by calling include method in LINQ query

Tracking changes

Date Page 25Author

• Proxy enabled mapping• Sharpshooting (self organized tracking)

Date: 11.02.2010Author: Marjan Nikolovski

Tracking changesProxy enabled mapping

Date Page 26Author

• Automatic tracking of changes in the Context

Date: 11.02.2010Author: Marjan Nikolovski

Tracking changesSharpshooting (self organized tracking)

Date Page 27Author

• Manual tracking of changes in the Context

Date: 11.02.2010Author: Marjan Nikolovski

Working with proxy enabled data

Date Page 28Author

• Enabling proxy enabled mapping and data manipulation

Date: 11.02.2010Author: Marjan Nikolovski

Working with proxy enabled dataEnabling proxy enabled mapping and data creation

Date Page 29Author

• ProxyCreationEnable property must be set to true• Creation of entity as proxy types

Date: 11.02.2010Author: Marjan Nikolovski

Serialization of proxy objects for WCF usage

Date Page 30Author

• What has to be done ?• One side implementation

Date: 11.02.2010Author: Marjan Nikolovski

Serialization of proxy objects for WCF usageWhat has to be done ?

Date Page 31Author

• Proxy object are objects of not known type• Defining service behavior where DataContractSerializer must be set

in order proxy data to be resolved to known type

Date: 11.02.2010Author: Marjan Nikolovski

Serialization of proxy objects for WCF usageOne side implementation

Date Page 32Author

Date: 11.02.2010Author: Marjan Nikolovski

Technology performance

Date Page 33Author

Date: 11.02.2010Author: Marjan Nikolovski

Pros and Cons

Date Page 34Author

• Object simplicity and great extensibility• Speeding up DAL design and implementation• Manual context synchronization can be tricky when comes to

business logic• Class construction overhead and memory overflow may occur when

no proper handling is used

Date: 11.02.2010Author: Marjan Nikolovski

Page 35Date: 11.02.2010Author: Marjan Nikolovski

Q&A

Page 36Date: 11.02.2010Author: Marjan Nikolovski

References

• http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-1-model-and-poco-classes/

• http://www.code-magazine.com/Article.aspx?quickid=0909081• http://byatool.com/tag/entity-framework/• http://msdn.microsoft.com/en-us/magazine/ee236639.aspx• http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-self-tracking-entities-for-the-entity-

framework.aspx• http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-poco-templates-for-the-entity-

framework.aspx• http://blogs.msdn.com/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-

experience.aspx• http://blogs.msdn.com/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-

tracking-with-poco.aspx• http://blogs.msdn.com/adonet/archive/2009/05/19/sneak-peek-using-code-generation-templates-

with-the-entity--framework-4-0.aspx• http://blogger.forgottenskies.com/?p=518• http://msdn.microsoft.com/en-us/magazine/ee335715.aspx• http://blogs.msdn.com/efdesign/

www.seavus.com

Thank You

top related