stephen forte dat401 from s in dat.speaker select s.bio; chief strategy officer of telerik certified...

23

Upload: margaretmargaret-fields

Post on 18-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International
Page 2: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Data Access Hacks and Shortcuts

Stephen ForteDAT401

Page 3: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

from s in dat.Speaker select s.Bio;Chief Strategy Officer of TelerikCertified Scrum MasterActive in the community:

International Conference Speaker for 12+ yearsRD, MVP and INETA Speaker Co-moderator & founder of NYC .NET Developers Group http://www.nycdotnetdev.comAuthor of SQL Server 2008 Developers Guide (MS Press)

MBA from the City University of New YorkPast:

CTO and co-founder of Corzen, Inc. (TXV: WAN)CTO of Zagat Survey

Page 4: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Agenda

ADO.NET: Passing a .NET Custom Collection to a Stored ProcedureLINQ: Understanding the difference between IEnumerable and IQueryable by eavesdropping on the server Entity Framework: Model Complex Relationships with ViewsSilverlight: Binding REST data to SilverlightDatabase Architecture: Pre-calculate and Transform Data for Faster Performance

Page 5: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Agenda

ADO.NET: Passing a .NET Custom Collection to a Stored ProcedureLINQ: Understanding the difference between IEnumerable and IQueryable by eavesdropping on the server Entity Framework: Model Complex Relationships with ViewsAstoria: Binding REST data to SilverlightDatabase Architecture: Pre-calculate and Transform Data for Faster Performance

Page 6: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Hack #1: Pass .NET Collection to SPs

SQL Server 2008 allows Table Valued Variables to be passed into a stored procedure (TVP)ADO .NET 3.51 allows a DataSet to be passed into a SP via a TVPYour custom .NET collection is a graph of the data you want to insert/change

Must implement IEnumerableCreate a C# 3.0 Extension method that takes any IEnumerable collection and converts to a DataSet

Call your stored procedure with yourcollection.ToDataSet()

Page 7: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Using TVPs and .NET 3.5 Extension Methodsdemo

Page 8: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Agenda

ADO.NET: Passing a .NET Custom Collection to a Stored ProcedureLINQ: Understanding the difference between IEnumerable and IQueryable by eavesdropping on the server Entity Framework: Model Complex Relationships with ViewsAstoria: Binding REST data to SilverlightDatabase Architecture: Pre-calculate and Transform Data for Faster Performance

Page 9: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Hack #2: Spying on Your Server

Use implicitly typed local variablesIEnumerable will execute locally (Linq to Objects, XML)IQueryable will convert your LINQ to TSQL and execute remotely

When executing remotely, LINQ queries will generate TSQL on your serverYou can spy on this SQL via code or even better, watch the whole conversation via SQL Server Profiler

Learning a very small amount about TSQL, Indices, and Execution Plans will make you a far better LINQ programmer

Page 10: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

LINQ to SQL, LINQ to EF, LINQ to ORM + SQL Server Profiler

demo

Page 11: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Agenda

ADO.NET: Passing a .NET Custom Collection to a Stored ProcedureLINQ: Understanding the difference between IEnumerable and IQueryable by eavesdropping on the server Entity Framework: Model Complex Relationships with ViewsAstoria: Binding REST data to SilverlightDatabase Architecture: Pre-calculate and Transform Data for Faster Performance

Page 12: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Hack #3: Deconstruct Complex Databases Before You Map Them

Some DBAs go overboard and super normalize the database

Hard to represent a relationship via too many joinsORMs/EF are supposed to do this for us; however, it creates difficult models to work with

Many models are just 1:1 representations of the databaseCreate a series of views that deconstruct your complex data and optimize those views with an indexUpdates? Use stored procedures or you can still model the tables and only use them for updates

Page 13: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Creating Views Out of Complex Data Relationships for EF

demo

Page 14: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Agenda

ADO.NET: Passing a .NET Custom Collectionto a Stored ProcedureLINQ: Understanding the difference between IEnumerable and IQueryable by eavesdropping on the server Entity Framework: Model Complex Relationships with ViewsAstoria: Binding REST data to SilverlightDatabase Architecture: Pre-calculate and Transform Data for Faster Performance

Page 15: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Hack #4: Silverlight Databinding to RESTful Data Services

Use LINQ to ADO .NET Data Services on the SL clientLeverage your investment in LINQ; however, you have to be 100% asynchronous

Hack:Encapsulate all the asynchronous LINQ calls into its own helper library using Generics

Beware of cross-domain issuesClientaccesspolicy.xmlWCF Web Service, then expose as RESTful data

Page 16: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Asynchronous ADO .NET Data Services Data Binding via LINQ to Astoria in Silverlight

demo

Page 17: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Agenda

ADO.NET: Passing a .NET Custom Collection to a Stored ProcedureLINQ: Understanding the difference between IEnumerable and IQueryable by eavesdropping on the server Entity Framework: Model Complex Relationships with ViewsAstoria: Binding REST data to SilverlightDatabase Architecture: Pre-calculate and Transform Data for Faster Performance

Page 18: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Hack #5: “Reporting DB” Design Pattern

Optimize for a high read environment with multiple views of the data and multiple data access strategies What data to move? Anything that can be derived from an OLTP database for high read

Reporting dataWeb view (Amazon catalog, not orders)

Traditionally “flatter”Some de-normalized aspectsPrevents query against normalized “raw” dataMust accept latencyGood implementation of XMLHighly indexed since the data is “published”

Page 19: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Building the Database for Database Readsdemo

Page 20: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

[email protected]://stephenforte.net

question & answer

Page 21: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

www.microsoft.com/teched

Sessions On-Demand & Community

http://microsoft.com/technet

Resources for IT Professionals

http://microsoft.com/msdn

Resources for Developers

www.microsoft.com/learningMicrosoft Certification and Training Resources

www.microsoft.com/learning

Microsoft Certification & Training Resources

Resources

Page 22: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

Complete an evaluation on CommNet and enter to win!

Page 23: Stephen Forte DAT401 from s in dat.Speaker select s.Bio; Chief Strategy Officer of Telerik Certified Scrum Master Active in the community: International

© 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.