SlideShare ist ein Scribd-Unternehmen logo
1 von 56
NYC Entity Framework Firestarter
Speakers
Entity Framework Firestarter Schedule
Thanks Microsoft For Hosting and Lunch
EF NYC Firestarter Part 1:   It’s Time to Look at Entity Framework Julie Lerman thedatafarm.com/blog twitter @julielerman
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
Why Entity Framework? NYC Entity Framework Firestarter, Sept 27th 2010 Object Relational Mapper ADO.NET Data Set ADO Record Set Entity Framework Object Spaces
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
ADO.NET Today & Tomorrow NYC Entity Framework Firestarter, Sept 27th 2010 DataSet Entity Framework LINQ to SQL
Model in Entity Framework Model First Database First New Database Legacy Database Code First NYC Entity Framework Firestarter, Sept 27th 2010 “M”
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
Time to Code A little modeling… A little querying… A little editing… A little saving… NYC Entity Framework Firestarter, Sept 27th 2010
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
Entity Framework Everywhere NYC Entity Framework Firestarter, Sept 27th 2010
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
 Part 2:What’s new in Entity Framework 4 EF NYC Firestarter Steve Bohlen unhandled-exceptions.com/blog twitter @sbohlen
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)
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
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
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)
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
(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
WCF and Self-Tracking Entities T4 template for self-tracking entities Passing objects across serialization boundaries
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
Explicit State Management ObjectContext.ApplyCurrentValues( ) Formerly ApplyPropertyChanges( ) in v1 ObjectContext.ApplyOriginalValues( ) ObjectStateEntry.ChangeState( ) Unchanged/Added/Modified/Deleted ObjectStateManager.ChangeRelationshipState( )
Code-Only Support ‘Feature CTP’ Classes  Entities Entities  Database (optionally) No Model Necessary Heavily Convention over Configuration
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
 Part 4:    Getting Started with POCOs in EF4 EF NYC Firestarter Julie Lerman thedatafarm.com/blog twitter @julielerman
Agenda Simple POCO Classes Leveraging Proxies Customizable T4 Code Generation NYC Entity Framework Firestarter, Sept 27th 2010
POCO Plain Old CLR Objects
Benefits Use existing classes Loose Coupling Classes have no dependency on EF Persistence Ignorance Unit Testing Repositories & Unit Of Work Patterns
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
POCO Support Basics Turn off code generation from EDMX “Convention” will auto-map classes/entities NYC Entity Framework Firestarter, Sept 27th 2010
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
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; }
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
Dynamic Runtime Proxy Classes ,[object Object]
Lazy Load
RelationshipsPerson class F5 Mark all Entity (model) Properties virtual Provides features similar to EntityObject Change notification Relationship management Lazy Loading
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
Code Gen POCOs from Model T4 T 4 Text Template Transformation Toolkit
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
 Part 5:    Disconnected Strategies for     ASP.NET & Services EF NYC Firestarter Julie Lerman thedatafarm.com/blog twitter @julielerman
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
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
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
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
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
What about? Graphs Lazy Loading Returning IQueryables Change Tracking
NYC Entity Framework Firestarter, Sept 27th 2010 Oh, goody…. time for code…
Disconnected Strategies Summary EF has inherent challenges across tiers New tools in EF4 to enable disconnected NYC Entity Framework Firestarter, Sept 27th 2010
 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
Agenda Setting the stage Refactor a demo-worthy MVC app Explore an existing solution with more complexity
“-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
IObjectSet Abstraction IObjectSet Collection-like behavior Add, Attach, Delete, etc. ObjectSet Concrete class Implements IObjectSet Inherits ObjectQuery public class ObjectSet:ObjectQuery,IObjectSet
EF4 Goodness Makes This Work NYC Entity Framework Firestarter, Sept 27th 2010 POCOs + T4 Code Gen Disconnected Methods IObjectSet

Weitere ähnliche Inhalte

Ähnlich wie Entity Framework NYC Firestarter

Is Ef4 Ready For The Real Work
Is Ef4 Ready For The Real WorkIs Ef4 Ready For The Real Work
Is Ef4 Ready For The Real Work
Dennis Doomen
 

Ähnlich wie Entity Framework NYC Firestarter (20)

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
 
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelEntity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
 
Lerman Vvs13 Entity Framework 4 And Wcf
Lerman Vvs13 Entity Framework 4 And WcfLerman Vvs13 Entity Framework 4 And Wcf
Lerman Vvs13 Entity Framework 4 And Wcf
 
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
 
Entity Framework Today (May 2012)
Entity Framework Today (May 2012)Entity Framework Today (May 2012)
Entity Framework Today (May 2012)
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Is Ef4 Ready For The Real Work
Is Ef4 Ready For The Real WorkIs Ef4 Ready For The Real Work
Is Ef4 Ready For The Real Work
 
Applying EF Code First at Your Job
Applying EF Code First at Your JobApplying EF Code First at Your Job
Applying EF Code First at Your Job
 
Entity Framework 4 and WCF
Entity Framework 4 and WCFEntity Framework 4 and WCF
Entity Framework 4 and WCF
 
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)
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
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?
 
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)
 
Pomeriggio Entity Framework - Database First
Pomeriggio Entity Framework - Database FirstPomeriggio Entity Framework - Database First
Pomeriggio Entity Framework - Database First
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
.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)
 
Entity Framework v2 Best Practices
Entity Framework v2 Best PracticesEntity Framework v2 Best Practices
Entity Framework v2 Best Practices
 
Architecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity FrameworkArchitecting Smarter Apps with Entity Framework
Architecting Smarter Apps with Entity Framework
 
Diving Into Entity Framework Code First
Diving Into Entity Framework Code FirstDiving Into Entity Framework Code First
Diving Into Entity Framework Code First
 

Mehr von 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
 

Mehr von Julie Lerman (19)

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
 
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
 
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
 
AgileEntity Framework 4
AgileEntity Framework 4AgileEntity Framework 4
AgileEntity Framework 4
 
Lerman Adx303 Entity Framework 4 In Aspnet
Lerman Adx303 Entity Framework 4 In AspnetLerman Adx303 Entity Framework 4 In Aspnet
Lerman Adx303 Entity Framework 4 In Aspnet
 
Lerman Vvs14 Ef Tips And Tricks
Lerman Vvs14  Ef Tips And TricksLerman Vvs14  Ef Tips And Tricks
Lerman Vvs14 Ef Tips And Tricks
 
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
 
Data in the Azure Cloud, by Julie Lerman
Data in the Azure Cloud, by Julie LermanData in the Azure Cloud, by Julie Lerman
Data in the Azure Cloud, by Julie Lerman
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Entity Framework NYC Firestarter

  • 1. NYC Entity Framework Firestarter
  • 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.
  • 39. RelationshipsPerson 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