Presented by: Scott Guthrie
These are some “live” notes, written during the presentation. They will, necessarily, be a bit rough.
Introductions. “Scott, the father of ASP.NET”
LINQ is a new way to think about data that has ideas applicable to other languages, not just .NET languages.
Working with Data
Querying and manipulating data is fundamental part of a programmer’s job. Data formats change, but core needs remain the same.
Data access code in 1980s with DBASE has a certain elegance, and while we evolved more powerful language constructs, the APIs in the 1990s/early 2000s are way more complex and far from elegant. Very procedural and far from the data.
Object/Relational Mapping is big leap forward and provides a cleaner integration of business rules. But, it has limitations, like how to query data from a variety of sources. O/R mappers are for relational, but what about web services, XML, RSS, REST, etc.? There is also a disconnect between data schema and how we represent and transform the data in object form.
Introducing LINQ
Take the ideas of Query, Set, and Transform Operations and make them first-class citizens of .NET. Works with Relational, XML, Objects. Works with all .NET languages (both C# and VB have integrated support). Works with both static typed and dynamic languages (going into IronPython compiler!).
The language provides a syntax to create query expression against any kind of data.
Demo
O/R not a core component, but ships with it as an abstraction on top of LINQ. Scott creates some models in the VS GUI that link to the relational database tables. Automatically linked together according to schema. These are the core O/R that will be used to query against.
Is going to query for product information and price using a simple template.
var query = from p in db.Products
select p;
DataList1.DataSource = query;
DataList1.DataBind();
UI is populated.
Can use native VS debugger to introspect LINQ, so you always know what is going on. Demos using debugger. You can look at the raw SQL and the data returned.
Anonymous types allow you to define new type on the fly, to modify the columns returned. Also showed how to dynamically calculate a new column (i.e. revenue in this case). Can also compose queries across languages. Very cool. The raw SQL is pretty long and cumbersome. Impressive.
Shows example of using LINQ with XML file. Instead of XQuery, using the same LINQ syntax to query the XML. No iterating over TextReader!
Shows binding against collection of objects. Uses GetProcesses() to get some info about processes and uses a LINQ query to find those processes that start with the letter “i” and have a WorkingSet of a certain size. Cool.
You can also combine data from these various sources and join them together, which creates a new dynamic object on the fly which the control can bind against.
End of demo.
Declarative Intent
LINQ can be thought of as an internal DSL that makes life simpler for query and transform operations. Describe what not how you want things done. The industry is moving in this direction. Moving towards declarative intent is not just about productivity. It can help you significantly improve performance and better utilize multi-core processors, for instance. Currently, we use a very imperative way to do things and the imperative logic flow dictates the algorithm to use. It’s very single threaded and won’t utilize multiple cores. We need to move to a model that takes advantage of the other cores. Declarative intent programming can allow programmers to write code that is optimized “under the covers” for the multiple core environment, so the developer doesn’t need to know all about doing the threading for multiple cores. The query can express what we want instead of how to get it.
Summary
- LINQ makes query first class part of programming platform
- enables queries against objects, relational data, XML, or any custom domain
- Support for al .NET languages
- Built-in to .NET and Visual Studio “Orcas” release later this year
Fin.
Post a Comment