Entity Framework 4 Deep Dive

Slides:



Advertisements
Similar presentations
Shyam Pather Development Manager Microsoft Session Code: DTL402.
Advertisements

Tim Laverty – Diego Vega – Program Managers Microsoft Corporation SESSION CODE: DEV305.
How We Do Language Design at Microsoft (C#, Visual Basic, F#)
Tech·Ed North America /6/2018 2:20 AM
Tech·Ed  North America /11/ :01 AM SESSION CODE: DEV405
6/12/ :53 PM DEV311 Deep Dive into Microsoft Visual Studio Team Foundation Server 2010 Reporting Steven Borg, Principal ALM Consultant Northwest.
6/26/2018 9:02 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Tech·Ed North America /31/2018 4:35 PM
9/11/2018 5:53 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
MDOP: Advanced Group Policy Management 4.0
Tech Ed North America /13/ :13 AM Required Slide
Tech·Ed North America /14/2018 7:13 PM
Excel Services Deployment and Administration
Microsoft Visual Studio IDE Futures
Overview of Social Computing in Microsoft SharePoint 2010
Customer Experiences With Business Intelligence
Implementing RESTful Services Using the Microsoft .NET Framework
Sysinternals Tutorials
T-SQL Power! The OVER Clause: Your Key to No-Sweat Problem Solving
Tech·Ed North America /19/ :44 PM
What’s New In ASP.NET MVC 2
Matt Masson Software Development Engineer Microsoft Corporation
Advanced Dashboard Creation Using Microsoft SharePoint Server 2010
Jason Zander Unplugged
Branching and Merging Practices
Accessing Data in a .NET Web Application
Tech Ed North America /27/ :47 PM Required Slide
Delivering an End-to-End Business Intelligence Solution
Tech·Ed North America /4/2018 2:51 AM
12/5/2018 3:24 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Best Practices: Creating OData Services using WCF Data Services
Tech·Ed North America /7/2018 2:51 PM
Team Foundation Server 2010 for Everyone
Introducing Microsoft SQL Server 2008 R2 Master Data Services
Authoring for Microsoft Silverlight 4 with Microsoft Expression Blend
Data Driven ASP.NET Web Forms Applications Deep Dive
Tech Ed North America /1/ :36 AM Required Slide
Tech Ed North America /1/2019 2:58 AM Required Slide
Intro to Workflow Services and Windows Server AppFabric
Tech·Ed North America /2/2019 4:47 PM
DEV410: Deep Dive into Team Foundation Server 2012 Reporting
Microsoft Visual Studio 2010 for Web Deployment
Tech·Ed North America /17/2019 1:47 AM
1/17/2019 9:05 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
TechEd /18/2019 2:43 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Microsoft SharePoint Conference 2009 Jon Flanders
Peter Provost Sr. Program Manager Microsoft Session Code: DEV312
Tech·Ed North America /22/2019 7:40 PM
Building Silverlight Apps with RIA Services
From Development to Production: Optimizing for Continuous Delivery
TechEd /3/ :48 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Creating and Consuming OData Services for Business Applications
Sayed Ibrahim Hashimi Program Manager Microsoft Corporation
Tech Ed North America /12/2019 6:45 AM Required Slide
From Development to Production: Optimizing for Continuous Delivery
Brandon Bray Principal Group Program Manager Microsoft Corporation
A Lap Around Internet Explorer 9 For Developers
2010 Microsoft BI Conference
Tech·Ed North America /25/ :53 PM
Hack-proofing your Clients using Windows 7 Security!
How and When to Use MEF: Too Much Is Never Enough
Tech Ed North America /27/ :04 AM Required Slide
Building RESTful services using OData
Lap Around the Windows Azure Platform
Code First Development in Microsoft ADO.NET Entity Framework 4.1
Building BI applications using PowerPivot for Excel
7/5/2019 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Tech·Ed North America /6/2019 7:10 PM
Tech Ed North America /6/2019 2:07 PM Required Slide
What’s New in Visual Studio 2012 for Web Developers
Presentation transcript:

Entity Framework 4 Deep Dive Tech Ed North America 2010 5/15/2018 4:47 AM Required Slide SESSION CODE: DEV305 Entity Framework 4 Deep Dive Tim Laverty – timlav@microsoft.com Diego Vega – diego.vega@microsoft.com Program Managers Microsoft Corporation © 2010 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.

Goals Answers to common “depth” questions Focus on real-world scenarios Shortcomings of EF and workarounds

Agenda How do I: Map classes to database structures? Use patterns such as Repository? Write unit tests for apps using EF? Use EF in disconnected scenarios? Improve EF query perf?

How do I map classes to database structures? EF allows flexibility in mapping relational structures to OO structures Common mapping questions: Inheritance Mapping a single table to multiple entities Mapping Stored Procedures

Tech Ed North America 2010 Tim Laverty Program Manager Microsoft Mapping Tim Laverty Program Manager Microsoft DEMO © 2010 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.

EF Mapping Capabilities Inheritance Table per Hierarchy Table per Type Table per Concrete Type Hybrids Many entities to one table Stored Procedures Many tables to one entity Abstract Entities Associations within EntitySets Associations across EntitySets Store-side discriminators EDM-side discriminators QueryViews, Defining Query, CommandText

Repository Pattern – Overview Why: Cleaner separation of concerns Greater control Easier testability How: Simple class with simple interface Pretends to be just a collection Runs queries & updates on the application’s behalf Data Access Framework Database Business logic, UI, etc. Repository Data Access Framework Database

Repository Pattern using Entity Framework Diego Vega Program Manager Microsoft Corporation Demo

Repository Pattern – Recap Repositories are easy with EF! Best Practices: Make the repository’s interface as simple as possible Create separate repositories for each “aggregate” Keep other layers “persistence ignorant” Multiple repositories can share same ObjectContext as “unit of work” Popular additions: Query methods return IQueryable<T> Using “specification pattern”, e.g. repository.Find(c=>c.Id == id) Repository<T> base class

Testability using Entity Framework Why: Test business logic, not database Lightning fast unit tests! How: swap data access code with in-memory test doubles Choice #1: replace repository Choice #2: replace context interface LINQ only Repository ObjectContext Database Business logic, UI, etc. Real Repository Fake for context interface In-memory data Fake Repository In-memory data

Testability using Entity Framework Diego Vega Program Manager Microsoft Corporation Demo

Testability with Entity Framework – Recap Testability is easy with EF4! Best practices: Build simple repository interface Swap repository with in-memory test double Alternate route: define simple interface for context Still run tests against database often Things to avoid: Don’t try to mock the data access framework!

N-Tier with Entity Framework Why: App split by machine boundary Need to serialize object graphs Save changes made elsewhere How: use WCF with Self-Tracking Entities WCF Data Services, OData WCF RIA Services Your own data transfer objects Data Access Database Presentation Business logic

Self-Tracking Entities Diego Vega Program Manager Entity Framework Demo

N-Tier with Entity Framework – Recap EF4 N-Tier improvements: New low level state management API Self-Tracking Entities Best practices: Use standard change tracking when possible Use Self-Tracking Entities if sharing entity types is acceptable Create data transfer objects when low coupling is needed Other technologies to learn about: WCF Data Services - bit.ly/learndataservices WCF RIA Services - bit.ly/learnriaservices

How do I improve EF perf? – Factors Query complexity and use Model size and complexity Inheritance hierarchies Database Schema Design

Strategies for making EF queries run faster Tech Ed North America 2010 5/15/2018 4:47 AM Strategies for making EF queries run faster Tim Laverty Program Manager Microsoft DEMO © 2010 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.

EF load steps for startup and on first query? EF Startup Loads Model Metadata Generates EF Query Views (or upon first query) First Time Query Execution EF Query Translation EF Query Caching Manual with LINQ queries. Result Shaper Caching

How do I improve EF query perf – Recap Round trips Lazy Loading Multiple Queries Connection Overuse Danger! Use Include No Updates! Use NoTracking Expensive 1st time Cached Compile Query Large data No Updates! Projection Separate Queries EF offers fixup Stored Procs/Views Not Composable

Related Content Required Slide Speakers, please list the Breakout Sessions, Interactive Sessions, Labs and Demo Stations that are related to your session. Tech Ed North America 2010 5/15/2018 4:47 AM Related Content DEV324: Data Development GPS: Guidance for Choosing the Right Data Access Technology – Monday | 1:00 – 2:15 PM | Rm 383 DEV208: Open Data for the Open Web – Tuesday | 5:00 – 6:15 PM | Rm 279 DEV205: Overview of the Microsoft ADO.NET Entity Framework – Wednesday | 1:30 – 2:45 PM | Auditorium B DEV303: Building RESTful Applications with the Open Data Protocol – Wednesday | 3:15 – 4:30 PM | Rm 283 DEV323: Best Practices: Creating OData Services Using WCF Data Services – Wednesday | 5:00 – 6:15 PM | Rm 295 ARC306: Open Data for the Enterprise – Thursday | 8:00 – 9:15 AM | Rm 288 BOF05-DV: Microsoft ADO.NET Entity Framework 4.0: What’s Your Take? – Thursday | 9:45-11:00 AM DEV13-HOL: Building Applications and Services Using Open Data Protocol DEV11-HOL: Using the Entity Framework in Microsoft .NET Framework 4.0 and Microsoft Visual Studio 2010 TLC-77: Microsoft SQL Server R2 Data Development (ADO.NET, OData, XML) – TLC Yellow © 2010 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.

Additional Resources and Announcements MSDN Data Developer Center: http://msdn.com/data ADO.NET Team Blog: http://blogs.msdn.com/adonet OData Blog: http://odata.org/blog WCF Data Services Team Blog: http://blogs.msdn.com/astoriateam EF Design Blog: http://blogs.msdn.com/efdesign Data Platform Development Forums: http://msdn.com/data and click on the “Forums” tab Patterns and Testability: http://bit.ly/learnef4test, http://bit.ly/ef4wpfsample Come to the Data Development station in the DAT Track Area (yellow section of the TLC) to register for a Zune HD give-away!

Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. Tech Ed North America 2010 5/15/2018 4:47 AM Track Resources Visual Studio – http://www.microsoft.com/visualstudio/en-us/ Soma’s Blog – http://blogs.msdn.com/b/somasegar/  MSDN Data Developer Center – http://msdn.com/data ADO.NET Team Blog – http://blogs.msdn.com/adonet WCF Data Services Team Blog – http://blogs.msdn.com/astoriateam EF Design Blog – http://blogs.msdn.com/efdesign © 2010 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.

Resources Learning Required Slide www.microsoft.com/teched Tech Ed North America 2010 5/15/2018 4:47 AM Required Slide Resources Learning Sessions On-Demand & Community Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning Resources for IT Professionals Resources for Developers http://microsoft.com/technet http://microsoft.com/msdn © 2010 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.

Complete an evaluation on CommNet and enter to win! Tech Ed North America 2010 5/15/2018 4:47 AM Required Slide Complete an evaluation on CommNet and enter to win! © 2010 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.

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st http://northamerica.msteched.com/registration   You can also register at the North America 2011 kiosk located at registration Join us in Atlanta next year

Tech Ed North America 2010 5/15/2018 4:47 AM © 2010 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. © 2010 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.

Appendix

Required Slide Tech Ed North America 2010 5/15/2018 4:47 AM © 2010 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.