LINQ to Relational in Visual Studio 2008 SP1

Post on 10-May-2015

1,212 views 1 download

Tags:

description

LINQ to Relational in VS 2008 Sp1

transcript

1

LINQ to “Relational” (L2R) inVisual Studio 2008 SP 1

Mike TaultyDeveloper & Platform GroupMicrosoft LtdMike.Taulty@microsoft.com http://www.miketaulty.com

Where Are We?

“Traditional” ADO.NET Data Access

App CodeApp Code

Customers

ADO.NETADO.NET

DataReaderDataReader

Customers

CommandCommand

““SELECT * SELECT * FROM CUSTOMERS”FROM CUSTOMERS”

DataSetDataSet

“Traditional” ADO.NET Data AccessApp CodeApp Code

Customers

ADO.NETADO.NETLayerLayer

DataReaderDataReader

Customers

CommandCommand

““SELECT * SELECT * FROM CUSTOMERS”FROM CUSTOMERS”

DataDataObjectObject

Load()Load()

CustomerCustomer

FirstNamFirstNameeLastNamLastNamee

......

CustomerCustomer

FirstNamFirstNameeLastNamLastNamee

......

CustomerCustomer

FirstNamFirstNameeLastNamLastNamee

......

CustomerCustomer

FirstNamFirstNameeLastNamLastNamee

......

ORMORM

Language Integrated Queryfrom data in someDataSourcejoin otherData in someOtherSource on keyExpr equals keyExpr (into itemName)?let someVariable = someExpressionwhere somePredicateorderby (expression (ascending | descending)?)*select expressiongroup expression by keyExpression into itemName

.NET Framework V3.5 Service Pack 1.NET Framework V3.5 Service Pack 1

Language Features ( C# V3 and VB V9 )Language Features ( C# V3 and VB V9 )

CustoCustomm

ObjeObjectscts XMLXML SQLSQL EntitiEntiti

eses

6

LINQ is not just relational

Two Different Styles of LINQ from data in someDataSourcejoin otherData in someOtherSource on keyExpr equals keyExpr (into itemName)?let someVariable = someExpressionwhere somePredicateorderby (expression (ascending | descending)?)*select expressiongroup expression by keyExpression into itemName

IEnumerable<TIEnumerable<T>>

IQueryable<T>IQueryable<T>

8

IEnumerable/IQueryable

LINQ is about Query

LINQ specifies a standard syntax for querying dataLINQ has no standard syntax for modifying dataDifferent API’s take a different approach

LINQ to Objects has no approach – unneccessaryLINQ to XMLLINQ to SQLLINQ to Entities

LINQ to Relational ( “L2R” )

LINQ to SQL.NET Framework V3.5SQL Server databases – 2000, 2005, 2008 & CEUses existing ADO.NET SQL Provider

ADO.NET Entity Framework (“LINQ to Entities”).NET Framework V3.5 Service Pack 1Database agnosticNeeds modified ADO.NET Providers

Microsoft ships SQL and example Oracle providerVarious 3rd party providers in progress

L2R – Commonality in Querying

App CodeApp Code

Customers

““LINQ”LINQ”

QueryableQueryableObjectObject

DataReaderDataReader

Customers

LINQLINQQueryQuery

CallCall

ExecuteExecute

ContextContext

GetQueryable<TGetQueryable<T>()>()

Execute<T>()Execute<T>()

CustomeCustomerrFirstNamFirstNam

eeLastNamLastNamee

......

CustomeCustomerrFirstNamFirstNam

eeLastNamLastNamee

......

CustomeCustomerrFirstNamFirstNam

eeLastNamLastNamee

......

Materialise objectsMaterialise objects

ADO.NETADO.NETProviderProvider

Translate to Translate to SQLSQL

ORMMetadata

CreateCreate

L2R – Commonality in Modifying

App CodeApp Code

Customers

““LINQ”LINQ”

ContextContext

CustomeCustomerrFirstNamFirstNam

eeLastNamLastNamee

......

CustomeCustomerrFirstNamFirstNam

eeLastNamLastNamee

......

CustomeCustomerrFirstNamFirstNam

eeLastNamLastNamee

......

““Create”<T>()Create”<T>()

““Delete”<T>Delete”<T>

SaveChanges()SaveChanges()

CreateCreate

DeleteDelete

UpdatUpdatee

StateState

Del Del DelIns Upd

SaveSaveADO.NETADO.NETProviderProvider

Translate to Translate to SQLSQL

ORMMetadata

L2R - Differences

14

LINQ to Relational

Resources

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