2 behind every great site, there is great data eric nelson developer evangelist microsoft uk
DESCRIPTION
3 Agenda Data Access Overview Data access over the years ORM anyone? LINQ and LINQ to SQL ADO.NET Entity Framework Drill into Entity Framework LINQ to Entities LINQ to SQL vs LINQ to Entities Using Entity Framework with ASP.NET Traditional ASP.NET ASP.NET Dynamic DataTRANSCRIPT
2
Behind every great site, there is great dataEric NelsonDeveloper EvangelistMicrosoft UKhttp://blogs.msdn.com/ericnel
3
AgendaData Access Overview
• Data access over the years• ORM anyone?• LINQ and LINQ to SQL• ADO.NET Entity Framework
Drill into Entity Framework • LINQ to Entities• LINQ to SQL vs LINQ to Entities
Using Entity Framework with ASP.NET
• Traditional ASP.NET• ASP.NET Dynamic Data
4
Data Access over the yearsAccessing data in 1990• O
DBC, embedded SQL
Accessing data in 2000• A
DO, Stored Procedures
Accessing data in 2005• A
DO.NET, Datasets, DataReaders
Accessing data in 2010• O
RM baby!
5
Sidebar: Object Relational MappingWhat is it?
– technique for working with relational tables as if they were objects in memory
– Intention is to hide away the complexity of the underlying tables and give a uniform way of working with data
Why use it?– Productivity– Retain database independence
Notes– There are many ORMs for .NET developers already in existence. E.g.
– LLBLGen Pro http://www.llblgen.com/– Nhibernate http://www.hibernate.org/343.html– EntitySpaces http://www.entityspaces.net/Portal/Default.aspx
6
How did we get here?ObjectSpaces “v1” – never shippedObjectSpaces “v2” – never shippedMicrosoft Business Framework – never shippedWinFS – never shippedLINQ to SQL - shipped November 2007LINQ to Entities - shipped August 2008
8
LINQ and LINQ to SQLWhat is it?
– LINQ is not about databases, it is about objects– LINQ = Language-Integrated Query
– Extensions to programming languages to query objects in memory– LINQ to SQL is not about databases, it is about SQL Server
Why use it?– Productivity!!!
Notes– We ship in .NET Framework 3.5
– LINQ to Objects – LINQ to XML– LINQ to Datasets– LINQ to SQL– LINQ to Entities – added in .NET Framework 3.5 SP1
– Others make LINQ to Flickr etc– www.linqpad.net
10
ADO.NET Entity FrameworkWhat is it?
– Provides tools and services to create an Entity Data Model– Maps entities to database tables
– Provides tools and services for working with an Entity Data Model– Includes ORM capabilities
Why use it?– Productivity– Work with SQL Server, Oracle, DB2 etc– When require complex mapping between entities and database tables– Strategic– Works great with ADO.NET Data Services
Notes– Just released!
11
Drill into ADO.NET Entity Framework
•Mapping conceptual to physical•Demo
Entity Data Model
•Traditional queryingEntity Client
•Object based access•DemoObject Services
Sidebar: LINQ to SQL vs LINQ to Entities 1/2
It depends...LINQ to SQL LINQ to Entities
Database Support SQL Server Many
Object Relational Mapping Capabilities
Simple Complex
Requires Attributed .NET Code
No Yes
Status Released Just Released
Sidebar: Similar – but not quite 2/2LINQ to SQL
– var products = from prod in db.Product– where prod.Color == "Blue"– select prod;
LINQ to Entities– var products = from prod in db.Product– where prod.Color == "Blue"– select prod;
In general – LINQ to Entities does more – but not always!Only migration that will ever happen is LINQ to SQL migration to LINQ to Entities
14
Entity Data ModelApplication model– Mapped to a persistence store
Comprised of three layers:– Conceptual (CSDL)– Mapping (MSL)– Storage (SSDL)
Database agnosticComprised of:– Entities– Associations– Functions
Conceptual
Mapping
Storage
Entity Data Model
16
Entity FrameworkEDM consumption options:– Entity Client
– Entity SQL– Object Services
– Entity SQL– LINQ To Entities
17
Entity ClientFamiliar ADO.NET object model:– EntityCommand– EntityConnection– EntityDataReader– Entity Parameter– EntityTransaction
Text-based resultsRead-onlyUses Entity SQL
18
Object ServicesQueries materialized as Objects– ObjectContext– ObjectQuery<T>
Built on top of Entity ClientTwo query options:– Entity SQL– LINQ
Runtime services:– Unit of work– Identity tracking– Eager/explicit loading
19
Entity Framework – Service StackLINQ To Entities
Object Services
Entity SQL
Entity Client
ADO.NET Provider
21
Using Entity Framework with ASP.NET
•New Entity Data SourceTraditional ASP.NET
•Rich web site scaffolding•Works with LINQ to SQL and LINQ to Entities
ASP.NET Dynamic Data
23
The future?
•Across MS Products and Technologies•E.g. Reporting Services?
Entity Framework more widely adopted
•Better ORM capabilities in LINQ to Entities•POCO supportRough edges removed
•Developed “in isolation”•e.g. ASP.NET Dynamic Data and Entity Framework
Technologies work better together
•Less xml editing during developmentBetter tooling
24
Conclusion
•Data Access technology remained reasonably static•Procedural, API access•Surfaced the database schema
1990 to 2007 - Tables
•LINQ – excellent addition to the .NET languages•Entity Framework and the EDM – strategic investment•Productivity leap
2008 - Objects
•Plenty more to come2009
25
Resourceshttp://blogs.msdn.com/ericnel - all the linksGeneral
– ADO.NET Team Blog http://blogs.msdn.com/adonet– Mike in our team http://www.miketaulty.com ( search Entity or LINQ )– Data Platform Developer Centre
http://msdn.microsoft.com/en-gb/data/default.aspx LINQ
– LINQPad http://www.linqpad.net/ADO.NET Entity Framework
– EF Lead PM http://blogs.msdn.com/dsimmons – FAQ http://blogs.msdn.com/dsimmons/pages/entity-framework-faq.aspx – Entity Framework Design http://blogs.msdn.com/efdesign/default.aspx
ADO.NET Data Services– Team blog http://blogs.msdn.com/astoriateam
26
AcronymsEDM = Entity Data Model
EF = ADO.NET Entity Framework
ESQL = Entity SQL
LINQ = Language Integrated Query
CSDL = Conceptual Schema Definition Language
SSDL = Store Schema Definition Language
MSDL = Mapping Schema Definition Language
Lambda Syntax = customer.Select(...)
Comprehension Syntax = from c in customer ...
SQL = Structured Query Language
27
Resources
www.microsoft.com/teched Tech·Talks Tech·Ed BloggersLive Simulcasts Virtual Labs
http://msdn.microsoft.com
Developer’s Kit, Licenses, and MORE!
http://microsoft.com/expression
Professional Design tools for tomorrow
28
© 2008 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.