language integrated query (linq) -...
TRANSCRIPT
![Page 1: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/1.jpg)
Language Integrated Query (LINQ)Martin ParryDeveloper & Platform GroupMicrosoft [email protected]://www.martinparry.com
![Page 2: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/2.jpg)
Introduction
We use many different types of query
SQL, XQuery/XPath, DataView row filters, etc.
Maybe we could enhance productivity by...
Deciding on one query expression syntax
Enabling compilers to check queries & results
Allow extensibility to target all kinds of data
![Page 3: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/3.jpg)
Agenda
C#3 and VB9 Language Enhancements
Building to LINQ to Objects
LINQ to XML
LINQ to SQL
LINQ to DataSets
![Page 4: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/4.jpg)
C#3 and VB9
Ship with Visual Studio 2008
Contain language features that enable LINQ
Necessary for LINQ, but not sufficient...
Also need .NET FX 3.5
Contains a lot of new classes that make LINQ work – we’ll see some later
![Page 5: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/5.jpg)
New Language Features – LINQ to objects
![Page 6: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/6.jpg)
Language Innovationsvar contacts =
from c in customers
where c.City == "Hove"
select new { c.Name, c.Phone };
var contacts =
customers
.Where(c => c.City == "Hove")
.Select(c => new { c.Name, c.Phone });
Extension methods
Lambda expressions
Query expressions
Object initializers
Anonymous types
Local variable type inference
![Page 7: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/7.jpg)
LINQ to XML
![Page 8: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/8.jpg)
LINQ to XML
Creating XMLConstructors lend themselves to nesting
Can use LINQ (over anything) to build XML
QueryingUse normal axes from XML infoset
Get full power of query expressions over XML
Select, where, group by, etc.
Xml Namespaces
![Page 9: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/9.jpg)
LINQ to SQL
![Page 10: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/10.jpg)
LINQ to SQL
DataContext is the central class
Use code-gen for ORM
SQL is only submitted when needed
Parent-child relationships are respected
Control of deferred loading
Can insert/update/delete
Transactionally, with concurrency checks
![Page 11: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/11.jpg)
LINQ to DataSet
![Page 12: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/12.jpg)
LINQ to DataSet
Query expressions over in-memory data
Works with untyped or typed DataSets
If query returns some kind of DataRow: -
Can yield results as a DataView
...and therefore databind to those results
![Page 13: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/13.jpg)
That’s LINQ
A combination of new language features, and new fx3.5 classes (with extension methods)
A common query expression syntax
Freedom to implement across different kinds of data
It’s TYPED...The compiler can check your queries
The compiler can check your results
![Page 14: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/14.jpg)
For more information
Today’s sample code via
http://www.martinparry.com
MSDN Nuggets by Mike Taulty
http://www.microsoft.com/uk/msdn/nuggets
![Page 16: Language Integrated Query (LINQ) - download.microsoft.comdownload.microsoft.com/documents/uk/msdn/events/... · Agenda C#3 and VB9 Language Enhancements Building to LINQ to Objects](https://reader030.vdocuments.net/reader030/viewer/2022040602/5e96a28cb5c8297ea3042763/html5/thumbnails/16.jpg)
© 2007 Microsoft Ltd. 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.