SlideShare ist ein Scribd-Unternehmen logo
1 von 27
ADO.NET Entity Framework in Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 Eric Nelson  eric.nelson@microsoft.com http://geekswithblogs.net/iupdateable http://twitter.com/ericnel Developer Evangelist Microsoft UK Advert Alert http://ukazure.ning.com
Agenda Swift intro to Entity Framework Entity Framework 4.0 Drill Down Lots of demos
Why an ORM? Why Entity Framework?
Why an ORM? Why Entity Framework?
ADO.NET Entity Framework Recap Entity Data Model Tools and services to create an Entity Data Model (EDM) Conceptual to Mapping to Storage Tools and services for consuming an Entity Data Model LINQ to Entities, Object Services and Entity SQL Together they address the “impedance mismatch”  Objects in  Applications Conceptual Mapping Storage Rows in  Tables
Model First and Templated Code Generation demo
Entity Framework 1.0 Features Generate model from database schema Very rich mapping layer Inheritance, rename, aggregate, filter Simplified CRUD operations LINQ querying* Worked with many databases Database agnostic query language SP support for data retrieval/modification* Designer* Strategic!
Entity Framework 1.0 - Too many pain points The designer! Model First not supported Poor support for Stored Procedures No Pluralization/Singularization Foreign Keys hidden Lazy Loading not supported Missing LINQ Operators vs LINQ to SQL Generated SQL unreadable No support for Plain Old CLR Objects N-Tier difficult
Entity Framework 4.0
New in ADO.NET Entity Framework 4.0 Model-first development Automatic pluralization Foreign keys in models POCO class support Lazy loading T4 Code Generation Template customization IObjectSet Virtual SaveChanges ObjectStateManager control Self-tracking entities SQL generation improvements More LINQ operator support LINQ extensibility ExecuteStoreQuery ExecuteStoreCommand SPROC import improvements Model defined functions WPF designer integration Code-Only development (Feature CTP)
Entity Framework 4.0 - Removing the friction Better Tools and Design Experience More powerful/flexible runtime And Persistence Ignorance* N-Tier Code Only* Note: * Delivered in .NET Framework 4 and a separate download
Better Tools and Design Experience Model First Templated code generation Stored Procedures Pluralization/Singularization Complex Types Better delete and search
Model First and Templated Code Generation demo
More powerful/flexible runtime Lazy loading Foreign Keys surfaced More complete LINQ implementation ExecuteStoreQuery EntityFunctions and SqlFunctions Improvements to generated SQL
Deferred Loading, Generated SQL demo
http://blogs.msdn.com/adonet/archive/2009/08/05/improvements-to-the-generated-sql-in-net-4-0-beta1.aspx
Feature Pack Separate download Contents T4 Template for Persistence Ignorance/POCO T4 Template for self-tracking entities (Now part of VS2010 RC) Code-only support When VS2010 is RTM, Feature Pack will be high quality.
Persistence Ignorance/POCO First class support for Persistence Ignorance  No modifications to your classes!
Persistence Ignorance demo
N-Tier (Self Tracking Entities) Service publicclassNorthwindService : INorthwindService {     publicCustomerGetCustomer(string id)     { using (varctx = newNorthwindEntities())         { returnctx.Customers.Include("Orders")                 .Where(c => c.CustomerID == id)                 .SingleOrDefault();         } } publicboolSubmitOrder(OrdernewOrder)     { using (varctx = newNorthwindEntities())         { ctx.Orders.ApplyChanges(newOrder); ValidateOrderGraph(ctx, newOrder); returnctx.SaveChanges() > 0;         } } } Client staticboolValidSTEUpdate(INorthwindService svc) { var customer = svc.GetCustomer("ALFKI"); // modify contact name of customer customer.ContactName += "+"; // add a new order varnewOrder = newOrder(); newOrder.Order_Details.Add(newOrder_Detail()  {  ProductID = products.Where(p => p.ProductName 	       == "Chai").Single().ProductID,             Quantity = 1         }); customer.Orders.Add(newOrder);    return svc.SubmitOrder(newOrder); } Danny Simmons MSDN Article: Building N-Tier Apps with EF4 http://code.msdn.microsoft.com/mag200911EF4  http://msdn.microsoft.com/en-gb/magazine/ee335715.aspx
N-Tier demo
Code Only Create the database from the classes No model Convention to config
Database First / Model First / CodeOnly Database First (EF v1) Model First Code Only
Code Only demo
Entity Framework  The designer! No support for Plain Old CLR Objects No Pluralization/Singularization Foreign Keys hidden Model First not supported Lazy Loading not supported Missing LINQ Operators vs LINQ to SQL Generated SQL unreadable N-Tier difficult Poor support for Stored Procedures
Summary Entity Framework 4.0 is rather nice! We continue to listen and improve Resources Entity Framework 4.0 Resources http://bit.ly/ef4resources Entity Framework Team Blog http://blogs.msdn.com/adonet/ Entity Framework Design Blog http://blogs.msdn.com/efdesign/
Required Slide © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation.  Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.  MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Weitere ähnliche Inhalte

Mehr von Eric Nelson

Windows Azure Platform best practices by ericnel
Windows Azure Platform best practices by ericnelWindows Azure Platform best practices by ericnel
Windows Azure Platform best practices by ericnelEric Nelson
 
Windows Azure Platform: Articles from the Trenches, Volume One
Windows Azure Platform: Articles from the Trenches, Volume OneWindows Azure Platform: Articles from the Trenches, Volume One
Windows Azure Platform: Articles from the Trenches, Volume OneEric Nelson
 
Looking at the clouds through dirty windows
Looking at the clouds through dirty windows Looking at the clouds through dirty windows
Looking at the clouds through dirty windows Eric Nelson
 
SQL Azure Overview for Bizspark day
SQL Azure Overview for Bizspark daySQL Azure Overview for Bizspark day
SQL Azure Overview for Bizspark dayEric Nelson
 
Building An Application For Windows Azure And Sql Azure
Building An Application For Windows Azure And Sql AzureBuilding An Application For Windows Azure And Sql Azure
Building An Application For Windows Azure And Sql AzureEric Nelson
 
Windows Azure In 30mins for none technical audience
Windows Azure In 30mins for none technical audienceWindows Azure In 30mins for none technical audience
Windows Azure In 30mins for none technical audienceEric Nelson
 
Dev305 Entity Framework 4 Emergency Slides
Dev305 Entity Framework 4 Emergency SlidesDev305 Entity Framework 4 Emergency Slides
Dev305 Entity Framework 4 Emergency SlidesEric Nelson
 
Design Considerations For Storing With Windows Azure
Design Considerations For Storing With Windows AzureDesign Considerations For Storing With Windows Azure
Design Considerations For Storing With Windows AzureEric Nelson
 
What Impact Will Entity Framework Have On Architecture
What Impact Will Entity Framework Have On ArchitectureWhat Impact Will Entity Framework Have On Architecture
What Impact Will Entity Framework Have On ArchitectureEric Nelson
 
Windows Azure Overview
Windows Azure OverviewWindows Azure Overview
Windows Azure OverviewEric Nelson
 
SQL Data Service Overview
SQL Data Service OverviewSQL Data Service Overview
SQL Data Service OverviewEric Nelson
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2Eric Nelson
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework OverviewEric Nelson
 
SQL Server 2008 Overview
SQL Server 2008 OverviewSQL Server 2008 Overview
SQL Server 2008 OverviewEric Nelson
 

Mehr von Eric Nelson (14)

Windows Azure Platform best practices by ericnel
Windows Azure Platform best practices by ericnelWindows Azure Platform best practices by ericnel
Windows Azure Platform best practices by ericnel
 
Windows Azure Platform: Articles from the Trenches, Volume One
Windows Azure Platform: Articles from the Trenches, Volume OneWindows Azure Platform: Articles from the Trenches, Volume One
Windows Azure Platform: Articles from the Trenches, Volume One
 
Looking at the clouds through dirty windows
Looking at the clouds through dirty windows Looking at the clouds through dirty windows
Looking at the clouds through dirty windows
 
SQL Azure Overview for Bizspark day
SQL Azure Overview for Bizspark daySQL Azure Overview for Bizspark day
SQL Azure Overview for Bizspark day
 
Building An Application For Windows Azure And Sql Azure
Building An Application For Windows Azure And Sql AzureBuilding An Application For Windows Azure And Sql Azure
Building An Application For Windows Azure And Sql Azure
 
Windows Azure In 30mins for none technical audience
Windows Azure In 30mins for none technical audienceWindows Azure In 30mins for none technical audience
Windows Azure In 30mins for none technical audience
 
Dev305 Entity Framework 4 Emergency Slides
Dev305 Entity Framework 4 Emergency SlidesDev305 Entity Framework 4 Emergency Slides
Dev305 Entity Framework 4 Emergency Slides
 
Design Considerations For Storing With Windows Azure
Design Considerations For Storing With Windows AzureDesign Considerations For Storing With Windows Azure
Design Considerations For Storing With Windows Azure
 
What Impact Will Entity Framework Have On Architecture
What Impact Will Entity Framework Have On ArchitectureWhat Impact Will Entity Framework Have On Architecture
What Impact Will Entity Framework Have On Architecture
 
Windows Azure Overview
Windows Azure OverviewWindows Azure Overview
Windows Azure Overview
 
SQL Data Service Overview
SQL Data Service OverviewSQL Data Service Overview
SQL Data Service Overview
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
 
Entity Framework Overview
Entity Framework OverviewEntity Framework Overview
Entity Framework Overview
 
SQL Server 2008 Overview
SQL Server 2008 OverviewSQL Server 2008 Overview
SQL Server 2008 Overview
 

Kürzlich hochgeladen

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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.pptxRemote DBA Services
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
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 2024Victor Rentea
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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)Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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 FMESafe Software
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
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...DianaGray10
 
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 FMESafe Software
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
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 Takeoffsammart93
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Kürzlich hochgeladen (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
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...
 
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
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Entity Framework 4 In Microsoft Visual Studio 2010

  • 1. ADO.NET Entity Framework in Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 Eric Nelson eric.nelson@microsoft.com http://geekswithblogs.net/iupdateable http://twitter.com/ericnel Developer Evangelist Microsoft UK Advert Alert http://ukazure.ning.com
  • 2. Agenda Swift intro to Entity Framework Entity Framework 4.0 Drill Down Lots of demos
  • 3. Why an ORM? Why Entity Framework?
  • 4. Why an ORM? Why Entity Framework?
  • 5. ADO.NET Entity Framework Recap Entity Data Model Tools and services to create an Entity Data Model (EDM) Conceptual to Mapping to Storage Tools and services for consuming an Entity Data Model LINQ to Entities, Object Services and Entity SQL Together they address the “impedance mismatch” Objects in Applications Conceptual Mapping Storage Rows in Tables
  • 6. Model First and Templated Code Generation demo
  • 7. Entity Framework 1.0 Features Generate model from database schema Very rich mapping layer Inheritance, rename, aggregate, filter Simplified CRUD operations LINQ querying* Worked with many databases Database agnostic query language SP support for data retrieval/modification* Designer* Strategic!
  • 8. Entity Framework 1.0 - Too many pain points The designer! Model First not supported Poor support for Stored Procedures No Pluralization/Singularization Foreign Keys hidden Lazy Loading not supported Missing LINQ Operators vs LINQ to SQL Generated SQL unreadable No support for Plain Old CLR Objects N-Tier difficult
  • 10. New in ADO.NET Entity Framework 4.0 Model-first development Automatic pluralization Foreign keys in models POCO class support Lazy loading T4 Code Generation Template customization IObjectSet Virtual SaveChanges ObjectStateManager control Self-tracking entities SQL generation improvements More LINQ operator support LINQ extensibility ExecuteStoreQuery ExecuteStoreCommand SPROC import improvements Model defined functions WPF designer integration Code-Only development (Feature CTP)
  • 11. Entity Framework 4.0 - Removing the friction Better Tools and Design Experience More powerful/flexible runtime And Persistence Ignorance* N-Tier Code Only* Note: * Delivered in .NET Framework 4 and a separate download
  • 12. Better Tools and Design Experience Model First Templated code generation Stored Procedures Pluralization/Singularization Complex Types Better delete and search
  • 13. Model First and Templated Code Generation demo
  • 14. More powerful/flexible runtime Lazy loading Foreign Keys surfaced More complete LINQ implementation ExecuteStoreQuery EntityFunctions and SqlFunctions Improvements to generated SQL
  • 17. Feature Pack Separate download Contents T4 Template for Persistence Ignorance/POCO T4 Template for self-tracking entities (Now part of VS2010 RC) Code-only support When VS2010 is RTM, Feature Pack will be high quality.
  • 18. Persistence Ignorance/POCO First class support for Persistence Ignorance No modifications to your classes!
  • 20. N-Tier (Self Tracking Entities) Service publicclassNorthwindService : INorthwindService { publicCustomerGetCustomer(string id) { using (varctx = newNorthwindEntities()) { returnctx.Customers.Include("Orders") .Where(c => c.CustomerID == id) .SingleOrDefault(); } } publicboolSubmitOrder(OrdernewOrder) { using (varctx = newNorthwindEntities()) { ctx.Orders.ApplyChanges(newOrder); ValidateOrderGraph(ctx, newOrder); returnctx.SaveChanges() > 0; } } } Client staticboolValidSTEUpdate(INorthwindService svc) { var customer = svc.GetCustomer("ALFKI"); // modify contact name of customer customer.ContactName += "+"; // add a new order varnewOrder = newOrder(); newOrder.Order_Details.Add(newOrder_Detail() { ProductID = products.Where(p => p.ProductName == "Chai").Single().ProductID, Quantity = 1 }); customer.Orders.Add(newOrder); return svc.SubmitOrder(newOrder); } Danny Simmons MSDN Article: Building N-Tier Apps with EF4 http://code.msdn.microsoft.com/mag200911EF4 http://msdn.microsoft.com/en-gb/magazine/ee335715.aspx
  • 22. Code Only Create the database from the classes No model Convention to config
  • 23. Database First / Model First / CodeOnly Database First (EF v1) Model First Code Only
  • 25. Entity Framework The designer! No support for Plain Old CLR Objects No Pluralization/Singularization Foreign Keys hidden Model First not supported Lazy Loading not supported Missing LINQ Operators vs LINQ to SQL Generated SQL unreadable N-Tier difficult Poor support for Stored Procedures
  • 26. Summary Entity Framework 4.0 is rather nice! We continue to listen and improve Resources Entity Framework 4.0 Resources http://bit.ly/ef4resources Entity Framework Team Blog http://blogs.msdn.com/adonet/ Entity Framework Design Blog http://blogs.msdn.com/efdesign/
  • 27. Required Slide © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Hinweis der Redaktion

  1. Look at the problems that EF addresses: - opaque database commands buried in strings - tedious, repetitive code to materialise objectsCreate connectionSQL String – embedded joinsDataReader – not type safe
  2. Type safe codeNo joins as we’ve abstracted away the database representation. (If we had joins then the compiler could verify them)Familiar query syntax (L2O, L2Xml, ...)Working with objects
  3. Some of the features of EF v1...Abstract the db model. Get a richer object/entity model to work with in the application. Isolate from change.Work with objects not tables. Have object relationships.Type-safe queries. Easy to query across relationships (just access properties on the objects!). Compile-time checking.Pretty good start, some rough areas. Mention vote of no confidence
  4. Yep, apparently “4” is the number after “1” in marketing ;-)Aligning version numbers with .NET 4, C#4. Don’t be alarmed if you see a reference to EF4!
  5. Code GenIn V1 we had EntityClassGenerator which could be configured using eventsHard (it used CodeDom)Inflexible (not much control)In V2 we will haveTemplatedEntityClassGenerator and will ship default T4 templatesCustomization via ToolsUses Workflow FoundationComplex typesPluralizationPublic abstract PluralizationServiceDefault implementation is English OnlyDefault rules:EntityTypes / ComplexTypes are singularizedEntitySets are pluralizedNavigation Properties based on cardinalityStored ProceduresStored Procedures as functionsMapping support for stored procedure resultComplex type as return typeScalar and void return typeEntity CUD using Stored ProceduresNo need to have SPs for all CUD
  6. Foreign KeysIndependent Association – v1 Product p = new Product { ID = 1,       Name = "Bovril",       Category = context.Categories                        .Single(c => c.Name == "Food") }; context.SaveChanges(); FK Association – v2 Product p = new Product     {         ID = 1,         Name = "Bovril",         CategoryID = 13     };     context.Products.AddObject(p);     context.SaveChanges();Deferred LoadingCan do lazy loadContext.deferredloading=true Model Level using ESQL<Function Name=“CustomerFullName” ReturnType=“String”><Parameter Name=“customer” Type=“MyModel.customer”> <DefiningExpression>customer.FirstName + ‘ ‘ + customer.LastName </DefiningExpression> </Function>Enables from c in ctx.Customers select c.FullName()CLR Level [EdmFunction("MyModel", "CustomerFullName")] public static string FullName(this customer c) { return String.Format("{0} {1}", c.FirstName, c.LastName); }Enables Console.WriteLine(c.FullName());Inline Functions in ESQL using Northwind;function AmountPurchased(c Customer) as Sum (c.Sales.Amt)function AmountReturned(c Customer) as Sum (c.Returns.Amt)function AmountConsumed(c Customer) as                                                                     AmountPurchased(c) – AmountReturned(c)select AmountConsumed(c) from Customers as c;
  7. Before going continuing, should mention the Feature Pack.Not all of the features I’m covering here will be in EF4 RTM, some (as mentioned in slide) will form the Feature Pack…
  8. N-Tier – exposing EF classes via WCF.Lots of feedback around the difficulties with detaching/reattaching object from contextNew API to makes this easier (context.ObjectStateManager.ChangeRelationshipState). Self-tracking Entities T4 template to make this even easier. Click through the example. Refer to great sample app by Danny Simmons for MSDN Magazine.N.B. Self tracking entity functionality requires type sharing between service and client
  9. Code OnlyNo XML files, no model!Convention to configE.g. Convention: xxxID to a primary key, schema=dboE.g. Config: On map to schema sys and class property to table column[TableMapping(Schema=“sys”,TableName=“MyDBTable”][ColumnMapping(PropertyName=“MyClassProp1”, ColumnName=“table_column1”)][Key(PropertyName=“MyClassProp1”)]public objectset<MyThing> MyThings...
  10. Db First (v1 approach)Model first. Start from scratch in designer. Generate code and database from model. Database generation is driven via a workflow that you can replace (haven’t looked at this yet!)Code first (feature pack). You create your classes in code and add some code to tell EF about the classes and their relationships. EF essentially creates a model internally and creates the database for you.