stephen forte dat401 from s in dat.speaker select s.bio; chief strategy officer of telerik certified...
Post on 18-Jan-2016
215 Views
Preview:
TRANSCRIPT
Data Access Hacks and Shortcuts
Stephen ForteDAT401
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
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
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
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()
Using TVPs and .NET 3.5 Extension Methodsdemo
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
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
LINQ to SQL, LINQ to EF, LINQ to ORM + SQL Server Profiler
demo
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
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
Creating Views Out of Complex Data Relationships for EF
demo
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
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
Asynchronous ADO .NET Data Services Data Binding via LINQ to Astoria in Silverlight
demo
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
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”
Building the Database for Database Readsdemo
stevef@orcsweb.comhttp://stephenforte.net
question & answer
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
Complete an evaluation on CommNet and enter to win!
© 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.
top related