Tech·Ed North America /5/2018 6:10 PM

Slides:



Advertisements
Similar presentations
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Robert LevyDoug Kramer Program ManagerDevelopment Lead DTL337.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Chris Menegay VP of Consulting Notion Solutions, Inc. DTL319.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Ram Cherala Principal Program Manager Microsoft Corporation DTL320.

Dmitry Sotnikov New Product Research Manager Quest Software DTL404.
customer.
Mickey Gousset Senior Technical Developer Infront Consulting Group Session Code: DTL330.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Eric Carter Development Manager Microsoft Corporation OFC324.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
Jonathan Aneja Program Manager Microsoft Corporation Session Code: DTL336 Anders Hejlsberg Technical Fellow Microsoft Corporation.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

Luke Hoban Senior Program Manager Microsoft Session Code: DTL319.
Mark Michaelis Chief Computer Nerd IDesign/Itron/IntelliTechture DTL313.
MIX 09 4/17/2018 4:41 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
How We Do Language Design at Microsoft (C#, Visual Basic, F#)
Tech·Ed North America /18/2018 2:05 PM
Tech·Ed North America /19/2018 3:29 PM
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 /7/2018 2:58 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.
Tech·Ed North America /14/2018 7:13 PM
Возможности Excel 2010, о которых следует знать
Sysinternals Tutorials
Tech·Ed North America /19/ :44 PM
11/22/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
11/22/2018 8:05 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Jason Zander Unplugged
Title of Presentation 12/2/2018 3:48 PM
Brian Keller Sr. Technical Evangelist Microsoft Session Code: DEV310
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.
Tech·Ed North America /7/2018 2:51 PM
12/27/ :01 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Data Driven ASP.NET Web Forms Applications Deep Dive
Tech Ed North America /1/ :36 AM Required Slide
Tech·Ed North America /2/2019 4:47 PM
Tech·Ed North America /17/2019 1:47 AM
Tech·Ed North America /17/2019 6:01 PM
Brian Keller Sr. Technical Evangelist Microsoft Session Code: DEV310
Building Silverlight Apps with RIA Services
Tech Ed North America /12/2019 6:45 AM Required Slide
Silverlight Debugging
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
A Lap Around Internet Explorer 9 For Developers
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Tech·Ed North America /25/ :53 PM
Hack-proofing your Clients using Windows 7 Security!
Шитманов Дархан Қаражанұлы Тарих пәнінің
Lap Around the Windows Azure Platform
Code First Development in Microsoft ADO.NET Entity Framework 4.1
Building BI applications using PowerPivot for Excel
Title of Presentation 5/24/2019 1:26 PM
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 /27/2019 6:20 AM
Tech·Ed North America /17/2019 4:14 PM
Tech·Ed North America /7/2019 2:30 PM
What’s New in Visual Studio 2012 for Web Developers
Presentation transcript:

Tech·Ed North America 2009 6/5/2018 6:10 PM © 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.

The ADO.NET Entity Framework: Tips & Tricks Tech·Ed  North America 2009 6/5/2018 6:10 PM The ADO.NET Entity Framework: Tips & Tricks Julie Lerman The Data Farm jlerman@thedatafarm.com DTL312 © 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.

Julie Lerman Mentor/Consultant jlerman@thedatafarm.com thedatafarm.com/blog LearnEntityFramework.com

10 Tips & Tricks Solving Pain Points Foreign Keys: Reading : Writing : Set Default Value Improve Inefficient Store Queries Use Random Results from Stored Procedures Use ObjectQuery methods with L2E Using EF More Effectively Create Generic Queries Find Exception Handling Details Encapsulate Query Execution Improve Query Performance

EF Model Hides Foreign Key ! EF Model Hides Foreign Key

1. Get FK Value When No Reference Object Is Available

2. Set Reference without Ref Object from Single EntityKey Property Order.CustomerReference.EntityKey = new EntityKey("MyEntities.Customers", "PersonID", 1) from Multiple EntityKey Properties var eKeyValues = new KeyValuePair<string, object>[] { new KeyValuePair<string, object>(“PropertyA", 12), new KeyValuePair<string, object>(“PropertyB", 103) }; EntityKey ekey= new EntityKey(“MyEntities", eKeyValues); instance.EntityRef.EntityKey=ekey;

3. Set Default Entity Reference Value Create Constructor in Entity's Partial Class C# Public Customer() { CustomerTypeReference.EntityKey = new EntityKey("MyEntities.CustomerTypes", “TypeID", 1) } VB Public Sub New() CustomerTypeReference.EntityKey = New EntityKey("MyEntities.CustomerTypes", “TypeID", 1) End Sub

Undesirable Store Queries ! Undesirable Store Queries LINQ to Entities Query From p In context.People Where p.LastName.StartsWith(“K") Resulting T-SQL Query SELECT [Extent1].[PersonID] AS [PersonID], ... WHERE (CAST(CHARINDEX(N'T', Extent1].[LastName]) AS int)) = 1

4. Control Store Query w/ ESQL Entity SQL SELECT VALUE p FROM EFEntities.People AS p WHERE p.LastName LIKE “T%” Query Builder Methods context.People.Where("it.LastName LIKE 'T%'") Resulting T-SQL SELECT [Extent1].[PersonID] AS [PersonID], WHERE [Extent1].[LastName] LIKE 'T%'

Bonus Tip! Testing ESQL Expressions eSql Blast! code.msdn.com/adonetefx

Stored Procs Return Non-Entity ! Stored Procs Return Non-Entity CREATE PROCEDURE OrdersBySalesPersonbyDate AS SELECT MIN(Person.FirstName) as First, MIN(Person.LastName) as Last, COUNT(Orderid) as OrderCount FROM … Requires lots of manual editing of the model, MSL and SSDL to create an entity that matches the return value

5. Use Views in Place of Sprocs CREATE VIEW OrdersBySalesPersonbyDate AS SELECT MIN(Person.FirstName) as First, MIN(Person.LastName) as Last, COUNT(Orderid) as OrderCount FROM … Wizard creates all entity metadata elements Other benefits View is composable Use in queries Change Tracking (use Stored Procs for DML)

ObjectQuery Special Methods in L2E ! ObjectQuery Special Methods in L2E Include from p in context.Orders.Include(“Customer”) select p OfType from p in context.People.OfType<Customer> MergeOption context.People.MergeOption=MergeOption.NoTracking; from p in context.People select p; Execute ??? ToTraceString

6. Cast L2E to Get ObjectQuery Methods var l2eQuery=from c in context.Customers select c ; var storeSQL=((ObjectQuery)l2eQuery).ToTraceString(); VB Dim l2eQuery=From c In context.Customers Select c Dim storeSQL = CType(l2eQuery, ObjectQuery).ToTraceString

! Redundant L2E Queries Country Reference List List<Country> GetCountries() { return context.Countries.OrderBy(c => c.Name) .ToList(); } Account Type Reference List List<AccountType> GetAccountTypes() { return context.AccountTypes.OrderBy(a => a.TypeName) Product Reference List List<Product> GetProducts() { return context.Products.OrderBy(p => p. Name)

7. Build Reusable, Generic Queries public static List<TEntity> GetReferenceList<TEntity> (this ObjectContext context) context.GetReferenceList<Country> context.GetReferenceList(Of AccountType) context.GetReferenceList<Product>

UpdateExceptions Anonymity ! UpdateExceptions Anonymity s Order B ? Person A Person B Order A db Error ? Person D Order C ? Order D Person C

8. ObjectStateEntry & Entity Instance Are Provided in UpdateExceptions

Redundant Code around Queries ! Redundant Code around Queries var query=from p in context.People select p; try { var people=query.ToList(); } catch (EntityException) { ... } Catch (CommandExecutionException) var query2=from o in context.Orders select o; try { var orders =query2.ToList(); } catch (EntityException) { ... } Catch (CommandExecutionException)

9. Encapsulate Query Execution Reusable Repository Methods public List<TEntity> ExecuteList<TEntity> (ObjectQuery<TEntity> objectQuery) (IQueryable<TEntity> L2EQuery) Calling Reusable Methods IEnumerable<Person> L2EQuery = from p in context.People select p; List<Person> people = dal.ExecuteList<Person>(L2EQuery); ObjectQuery oQuery = context.Orders; List<Order> orderList = dal.ExecuteList<Order>(oQuery);

Bonus Tip! Pre-Compile L2E Queries LINQ to Entities Query PreCompiled Query Store Query

Web Sites Lose Pre-Compiled L2E Queries ! Web Sites Lose Pre-Compiled L2E Queries Short-lived ObjectContext used to compile Pre-Compilation is repeated each time App process loses benefit of pre-compilation Big performance loss

10. Cache Pre-Compiled Query Func Class Level Static Function static Func<MyEntities, IQueryable<Customer>> customerPCQ; Class Constructor public CustomerProvider() { if (customerPCQ == null) customerPCQ = CompiledQuery.Compile<MyEntities, IQueryable<Customer>> (ctx => from cust in ctx.Customers where cust.Orders.Any() select cust ); }

EF4 Removes Some of the Pain Solving Pain Points Foreign Keys: Reading : Writing : Set Default Value Improve Inefficient Store Queries Use Random Results from Stored Procedures Use ObjectQuery methods with L2E Using EF More Effectively Create Generic Queries Find Exception Handling Details Encapsulate Query Execution Improve Query Performance

Contact Julie Lerman jlerman@thedatafarm.com thedatafarm.com/blog LearnEntityFramework.com

question & answer

Resources Required Slide Speakers, www.microsoft.com/teched TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings at TechEd Online. Resources www.microsoft.com/teched Sessions On-Demand & Community www.microsoft.com/learning Microsoft Certification & Training Resources http://microsoft.com/technet Resources for IT Professionals http://microsoft.com/msdn Resources for Developers www.microsoft.com/learning Microsoft Certification and Training Resources

Track Resources Visit the DPR TLC for a chance to win a copy of Visual Studio Team Suite. Daily drawing occurs every day in the TLC at 4:15pm. Stop by for a raffle ticket http://www.microsoft.com/visualstudio http://www.microsoft.com/visualstudio/en-us/products/teamsystem/default.mspx Please visit us in the TLC blue area

Complete an evaluation on CommNet and enter to win! Required Slide Complete an evaluation on CommNet and enter to win!

Required Slide 6/5/2018 6:10 PM © 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. © 2007 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.