SlideShare una empresa de Scribd logo
1 de 19
ADX303:
Options for Building ASP.NET
Web Sites with Entity Framework
Julie Lerman
www.thedatafarm.com
jlerman@thedatafarm.com
Julie Lerman
website
theDataFarm.com
blog & twitter
theDataFarm.com/blog
@julielermanVT
book web site
LearnEntityFramework.com
consultant/mentor
Microsoft MVP, INETA Speaker,
ASPInsider, MCP, VTdotNET Leader
Agenda
• Architectural Challenges
• EntityDataSource
• Dynamic Data
• ASP.NET MVC
• ObjectDataSource
• Architected n-Tier Web Forms
SaveChanges Creates db Commands
• Insert Command
• From: Current values
EntityState =
Added
• Delete Command
• From: EntityKey & FK values
EntityState=
Deleted
• UpdateCommand
• From: Current vs. Original
EntityState=
Modified
Change Tracking Across Tiers
ObjectContext
Sales
Order #1
Line
Item A
Line
Item B
Sales
Order #2
Line
Item C
Line
Item D
detach
entities
ObjectStateEntry
SO1 EntityKey
Original Values
Current Values
Other ∆ Info
ObjectStateEntry
SO2 EntityKey
Original Values
Current Values
Other ∆ Info
ObjectStateEntry
LIA EntityKey
Original Values
Current Values
Other ∆ Info
ObjectStateEntry
LIB EntityKey
Original Values
Current Values
Other ∆ Info
Original Property
Values
EntityState Values
SaveChanges Fails Across Post Backs
New Page
Class
Create New
ObjectContext
Get Entities
Build HTML using Data
& ASP.NET Markup
Destroy Page and
Dependents
Page Request
New Page
Class
Create New
ObjectContext
Process
Request
Build HTML using Data
& ASP.NET Markup
Destroy Page and
Dependents
Post Back #1
New Page
Class
Create New
ObjectContext
Get Entities
Build HTML using Data
& ASP.NET Markup
Destroy Page and
Dependents
Post Back #2
The ASP.net Spectrum with EF
Entity
Data
Source
Dynamic
Data for
Entities
Object
Data
Source
ADO.NET
Data
Services
WCF
n-Tier
Dev
Architect
MVC
EF4 Changes to the Rescue
• Foreign Keys
● Big help for data-binding related objects
• POCO Classes & T4 Generation
• State Methods
● ApplyCurrentValues, ApplyOriginalValues
● ChangeState
● ChangeRelationshipState (when no FKs)
EntityDataSource Control
• RAD
• Simple, Drag & Drop
• Lots of Event Handlers to tap into
Pros
• Data access tied to the UI
• Constrained by limitations of EDS
• Can’t update graphs
Cons
Dynamic Data Controls
• RAD
• Uses EntityDataSource
• Dynamically created from entities
• Can be customized
Pros
• Uses EntityDataSource
• DataAccess still bound to UICons
ASP.NET Model View Controller
• MVC Pattern using Entities as the model
• MVC Goal
● Separation of concerns
● Testable
• Entities as “Model”
• EF4’s POCO entities for better separation
ObjectDataSource Control
• Use your own business objects
• Repositories to interact with ObjectContext
• Lots of Event Handlers to tap into
Pros
• Classes must comply w ODS rules
• Lose ability to work with graphsCons
Classes
Queries
(Repository B)
Tests
UI
EF Classes in a Repository
System.Data.Entity
EDM &
ObjectContext
(Repository A)
Mock
Context A
Mock
ObjectSet
Mock
Context B
Julie Lerman Oredev 2009
Basic Pattern for ASP.NET n-Tier
Code
Behind
Business
Logic
Repository
Queries Cache
EntityKeys, Scalars
(inc FKs)
Foreign Keys make this
approach a possibility
MVC View
MVC
Controller Model &
ObjectContext
ASPX
N-Tier ASP.NET
• Serious challenges in EFv1
• Help in EF4
● POCO objects & T4 Code Generation
● Caching gets simpler
● Foreign Keys
● New n-Tier methods
• ChangeState, ApplyCurrentValues,
ApplyOriginalValues, ChangeRelationship
Caching Considerations
• SessionState vs ViewState vs Cache
• Cache with Velocity or MemCached
• Cache vs Refresh from DB for Updates?
• Roll your own? Use a provider?
• Anyway you go – it’s still HARD
Summary
• ASP.NET provides many ways to use EF
• New EF4 features expand possibilities
• RAD: Dynamic Data & EntityDataSource
• Business Layer “Lite”: ObjectDataSource
• MVC Benefits from POCOs
• Web Forms n-Tier helped by Foreign Keys
Julie Lerman
website
theDataFarm.com
blog & twitter
theDataFarm.com/blog
@julielermanVT
book web site
LearnEntityFramework.com
consultant/mentor
Microsoft MVP, INETA Speaker,
ASPInsider, MCP, VTdotNET Leader
Resources
• EF Team Blogs (blogs.msdn.com/)
● adonet, efdesign, dsimmons, adjames, more..
• Danny Simmons’ Aug 2009 MSDN Mag
• MS PAG: Data Access Guidance
● dataguidance.codeplex.com

Más contenido relacionado

La actualidad más candente

kranonit S04E02 Кирил Jstor: Hacking .NET applications
kranonit S04E02 Кирил Jstor: Hacking .NET applicationskranonit S04E02 Кирил Jstor: Hacking .NET applications
kranonit S04E02 Кирил Jstor: Hacking .NET applications
Krivoy Rog IT Community
 

La actualidad más candente (9)

Relay: Seamless Syncing for React (VanJS)
Relay: Seamless Syncing for React (VanJS)Relay: Seamless Syncing for React (VanJS)
Relay: Seamless Syncing for React (VanJS)
 
Intro to GraphQL
 Intro to GraphQL Intro to GraphQL
Intro to GraphQL
 
Angular
AngularAngular
Angular
 
kranonit S04E02 Кирил Jstor: Hacking .NET applications
kranonit S04E02 Кирил Jstor: Hacking .NET applicationskranonit S04E02 Кирил Jstor: Hacking .NET applications
kranonit S04E02 Кирил Jstor: Hacking .NET applications
 
Laravel 5 and SOLID
Laravel 5 and SOLIDLaravel 5 and SOLID
Laravel 5 and SOLID
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipes
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Angular 4 and TypeScript
Angular 4 and TypeScriptAngular 4 and TypeScript
Angular 4 and TypeScript
 
Project onion - Project Architecture for .Net Core Application
Project onion - Project Architecture for .Net Core ApplicationProject onion - Project Architecture for .Net Core Application
Project onion - Project Architecture for .Net Core Application
 

Similar a Lerman Adx303 Entity Framework 4 In Aspnet

Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic Unicorns
Richie Rump
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community
 
SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...
Liam Cleary [MVP]
 
What's New for Data?
What's New for Data?What's New for Data?
What's New for Data?
ukdpe
 

Similar a Lerman Adx303 Entity Framework 4 In Aspnet (20)

MVC and Entity Framework 4
MVC and Entity Framework 4MVC and Entity Framework 4
MVC and Entity Framework 4
 
ASP.NET MVC and Entity Framework 4
ASP.NET MVC and Entity Framework 4ASP.NET MVC and Entity Framework 4
ASP.NET MVC and Entity Framework 4
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 
Building n-Tier ASP.NET WebForms with Entity Framework 4, Lerman
Building n-Tier ASP.NET WebForms with Entity Framework 4, LermanBuilding n-Tier ASP.NET WebForms with Entity Framework 4, Lerman
Building n-Tier ASP.NET WebForms with Entity Framework 4, Lerman
 
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
dotNet Miami - June 21, 2012: Richie Rump: Entity Framework: Code First and M...
 
Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic Unicorns
 
Entity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sqlEntity framework core v3 from sql to no sql
Entity framework core v3 from sql to no sql
 
Entity framework 4.0
Entity framework 4.0Entity framework 4.0
Entity framework 4.0
 
Real-world Entity Framework
Real-world Entity FrameworkReal-world Entity Framework
Real-world Entity Framework
 
Entity Framework 4 In Microsoft Visual Studio 2010
Entity Framework 4 In Microsoft Visual Studio 2010Entity Framework 4 In Microsoft Visual Studio 2010
Entity Framework 4 In Microsoft Visual Studio 2010
 
Learn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstLearn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database First
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010
 
Entity Framework Today (May 2012)
Entity Framework Today (May 2012)Entity Framework Today (May 2012)
Entity Framework Today (May 2012)
 
SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...
 
04 integrate entityframework
04 integrate entityframework04 integrate entityframework
04 integrate entityframework
 
What's New for Data?
What's New for Data?What's New for Data?
What's New for Data?
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 

Más de Julie Lerman

Julie Lerman: Entity Framework FTQs (Frequently Tweeted Questions)
Julie Lerman: Entity Framework FTQs (Frequently Tweeted Questions)Julie Lerman: Entity Framework FTQs (Frequently Tweeted Questions)
Julie Lerman: Entity Framework FTQs (Frequently Tweeted Questions)
Julie Lerman
 
Julie Lerman Entity Framework in the Enterprise (Boston Code Camp March 2013)
Julie Lerman Entity Framework in the Enterprise (Boston Code Camp March 2013)Julie Lerman Entity Framework in the Enterprise (Boston Code Camp March 2013)
Julie Lerman Entity Framework in the Enterprise (Boston Code Camp March 2013)
Julie Lerman
 
Working With Sql Azure from Entity Framework On-Premises (Julia Lerman)
Working With Sql Azure from Entity Framework On-Premises (Julia Lerman)Working With Sql Azure from Entity Framework On-Premises (Julia Lerman)
Working With Sql Azure from Entity Framework On-Premises (Julia Lerman)
Julie Lerman
 

Más de Julie Lerman (20)

EF Core in Containerized ASP.NET Core APIs
EF Core in Containerized ASP.NET Core APIsEF Core in Containerized ASP.NET Core APIs
EF Core in Containerized ASP.NET Core APIs
 
Domain-Driven Design with Tender Loving Care (DDD with TLC)
Domain-Driven Design with Tender Loving Care (DDD with TLC)Domain-Driven Design with Tender Loving Care (DDD with TLC)
Domain-Driven Design with Tender Loving Care (DDD with TLC)
 
What's New in Visual Studio 2017
What's New in Visual Studio 2017What's New in Visual Studio 2017
What's New in Visual Studio 2017
 
A Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important FeaturesA Tour of EF Core's (1.1) Most Interesting & Important Features
A Tour of EF Core's (1.1) Most Interesting & Important Features
 
EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?EF6 or EF Core? How Do I Choose?
EF6 or EF Core? How Do I Choose?
 
Microsoft for developers open source and cross platform
Microsoft for developers  open source and cross platformMicrosoft for developers  open source and cross platform
Microsoft for developers open source and cross platform
 
Entity Framework and Domain Driven Design
Entity Framework and Domain Driven DesignEntity Framework and Domain Driven Design
Entity Framework and Domain Driven Design
 
RavenDB Overview
RavenDB OverviewRavenDB Overview
RavenDB Overview
 
Julie Lerman: Entity Framework FTQs (Frequently Tweeted Questions)
Julie Lerman: Entity Framework FTQs (Frequently Tweeted Questions)Julie Lerman: Entity Framework FTQs (Frequently Tweeted Questions)
Julie Lerman: Entity Framework FTQs (Frequently Tweeted Questions)
 
Julie Lerman Entity Framework in the Enterprise (Boston Code Camp March 2013)
Julie Lerman Entity Framework in the Enterprise (Boston Code Camp March 2013)Julie Lerman Entity Framework in the Enterprise (Boston Code Camp March 2013)
Julie Lerman Entity Framework in the Enterprise (Boston Code Camp March 2013)
 
Working With Sql Azure from Entity Framework On-Premises (Julia Lerman)
Working With Sql Azure from Entity Framework On-Premises (Julia Lerman)Working With Sql Azure from Entity Framework On-Premises (Julia Lerman)
Working With Sql Azure from Entity Framework On-Premises (Julia Lerman)
 
Perspectives on Entity Framework, Julie Lerman
Perspectives on Entity Framework, Julie LermanPerspectives on Entity Framework, Julie Lerman
Perspectives on Entity Framework, Julie Lerman
 
Entity Framework NYC Firestarter
Entity Framework NYC FirestarterEntity Framework NYC Firestarter
Entity Framework NYC Firestarter
 
Getting Persistence Ignorant with Entity Framework, Julie Lerman
Getting Persistence Ignorant with Entity Framework, Julie LermanGetting Persistence Ignorant with Entity Framework, Julie Lerman
Getting Persistence Ignorant with Entity Framework, Julie Lerman
 
Persistence Ignorance in Entity Framework 4, Julie Lerman
Persistence Ignorance in Entity Framework 4, Julie LermanPersistence Ignorance in Entity Framework 4, Julie Lerman
Persistence Ignorance in Entity Framework 4, Julie Lerman
 
Persistence Ignorance in Entity Framework 4, Julie Lerman
Persistence Ignorance in Entity Framework 4, Julie LermanPersistence Ignorance in Entity Framework 4, Julie Lerman
Persistence Ignorance in Entity Framework 4, Julie Lerman
 
Julie Lerman Agile Entity Framework (March 2010)
Julie Lerman Agile Entity Framework (March 2010)Julie Lerman Agile Entity Framework (March 2010)
Julie Lerman Agile Entity Framework (March 2010)
 
AgileEntity Framework 4
AgileEntity Framework 4AgileEntity Framework 4
AgileEntity Framework 4
 
Using Entity Framework's New POCO Features: Part 1, by Julie Lerman
Using Entity Framework's New POCO Features: Part 1, by Julie LermanUsing Entity Framework's New POCO Features: Part 1, by Julie Lerman
Using Entity Framework's New POCO Features: Part 1, by Julie Lerman
 
What's New in Entity Framework 4, by Julie Lerman
What's New in Entity Framework 4, by Julie LermanWhat's New in Entity Framework 4, by Julie Lerman
What's New in Entity Framework 4, by Julie Lerman
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 

Lerman Adx303 Entity Framework 4 In Aspnet

  • 1. ADX303: Options for Building ASP.NET Web Sites with Entity Framework Julie Lerman www.thedatafarm.com jlerman@thedatafarm.com
  • 2. Julie Lerman website theDataFarm.com blog & twitter theDataFarm.com/blog @julielermanVT book web site LearnEntityFramework.com consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leader
  • 3. Agenda • Architectural Challenges • EntityDataSource • Dynamic Data • ASP.NET MVC • ObjectDataSource • Architected n-Tier Web Forms
  • 4. SaveChanges Creates db Commands • Insert Command • From: Current values EntityState = Added • Delete Command • From: EntityKey & FK values EntityState= Deleted • UpdateCommand • From: Current vs. Original EntityState= Modified
  • 5. Change Tracking Across Tiers ObjectContext Sales Order #1 Line Item A Line Item B Sales Order #2 Line Item C Line Item D detach entities ObjectStateEntry SO1 EntityKey Original Values Current Values Other ∆ Info ObjectStateEntry SO2 EntityKey Original Values Current Values Other ∆ Info ObjectStateEntry LIA EntityKey Original Values Current Values Other ∆ Info ObjectStateEntry LIB EntityKey Original Values Current Values Other ∆ Info Original Property Values EntityState Values
  • 6. SaveChanges Fails Across Post Backs New Page Class Create New ObjectContext Get Entities Build HTML using Data & ASP.NET Markup Destroy Page and Dependents Page Request New Page Class Create New ObjectContext Process Request Build HTML using Data & ASP.NET Markup Destroy Page and Dependents Post Back #1 New Page Class Create New ObjectContext Get Entities Build HTML using Data & ASP.NET Markup Destroy Page and Dependents Post Back #2
  • 7. The ASP.net Spectrum with EF Entity Data Source Dynamic Data for Entities Object Data Source ADO.NET Data Services WCF n-Tier Dev Architect MVC
  • 8. EF4 Changes to the Rescue • Foreign Keys ● Big help for data-binding related objects • POCO Classes & T4 Generation • State Methods ● ApplyCurrentValues, ApplyOriginalValues ● ChangeState ● ChangeRelationshipState (when no FKs)
  • 9. EntityDataSource Control • RAD • Simple, Drag & Drop • Lots of Event Handlers to tap into Pros • Data access tied to the UI • Constrained by limitations of EDS • Can’t update graphs Cons
  • 10. Dynamic Data Controls • RAD • Uses EntityDataSource • Dynamically created from entities • Can be customized Pros • Uses EntityDataSource • DataAccess still bound to UICons
  • 11. ASP.NET Model View Controller • MVC Pattern using Entities as the model • MVC Goal ● Separation of concerns ● Testable • Entities as “Model” • EF4’s POCO entities for better separation
  • 12. ObjectDataSource Control • Use your own business objects • Repositories to interact with ObjectContext • Lots of Event Handlers to tap into Pros • Classes must comply w ODS rules • Lose ability to work with graphsCons
  • 13. Classes Queries (Repository B) Tests UI EF Classes in a Repository System.Data.Entity EDM & ObjectContext (Repository A) Mock Context A Mock ObjectSet Mock Context B Julie Lerman Oredev 2009
  • 14. Basic Pattern for ASP.NET n-Tier Code Behind Business Logic Repository Queries Cache EntityKeys, Scalars (inc FKs) Foreign Keys make this approach a possibility MVC View MVC Controller Model & ObjectContext ASPX
  • 15. N-Tier ASP.NET • Serious challenges in EFv1 • Help in EF4 ● POCO objects & T4 Code Generation ● Caching gets simpler ● Foreign Keys ● New n-Tier methods • ChangeState, ApplyCurrentValues, ApplyOriginalValues, ChangeRelationship
  • 16. Caching Considerations • SessionState vs ViewState vs Cache • Cache with Velocity or MemCached • Cache vs Refresh from DB for Updates? • Roll your own? Use a provider? • Anyway you go – it’s still HARD
  • 17. Summary • ASP.NET provides many ways to use EF • New EF4 features expand possibilities • RAD: Dynamic Data & EntityDataSource • Business Layer “Lite”: ObjectDataSource • MVC Benefits from POCOs • Web Forms n-Tier helped by Foreign Keys
  • 18. Julie Lerman website theDataFarm.com blog & twitter theDataFarm.com/blog @julielermanVT book web site LearnEntityFramework.com consultant/mentor Microsoft MVP, INETA Speaker, ASPInsider, MCP, VTdotNET Leader
  • 19. Resources • EF Team Blogs (blogs.msdn.com/) ● adonet, efdesign, dsimmons, adjames, more.. • Danny Simmons’ Aug 2009 MSDN Mag • MS PAG: Data Access Guidance ● dataguidance.codeplex.com