codemash pt 3
January 19, 2007
Scott Guthrie is giving a keynote about LINQ - Language INtegrated Query, a new data processing approach from MS.
talked about migration from Dbase-era, to mid 90s, to OO mapping approach today (hibernate, active record, etc).
Still have issues:
- how do you deal with non-relational data?
- how do you interactive with ‘plain old objects’?
- how to enable rich data shaping/transformations (flexible query composition that is fast)?
- how to get clean code in both strong and dynamic typing environments?
LINQ is query, set and transform operations for .net Makes querying data a core programming concept, not an add-on.
Not language specific? Print python result, process in VB, pass to c# for display (example)
Example code:
var query = from p in db.products where p.category.categoryname==’drink’ select p;
DataList1.Datasource = query;
DataList1.DataBind();
categoryname is part of a category, and category is related to products in an o/r map set up elsewhere in the project. neat!
debugging - hover over the ‘query’ value and it’ll show the raw SQL - I assume that’s only for sources that are SQL based. Wouldn’t see SQL for hitting an XML file.
change ’select’ to ’select new {p.productName, p.price} and you’ll get a new object. Can also create new ‘columns’ (properties) dynamically (example was adding a revenue property which summed the price * number in related order table).
Added .skip and .take methods at end of query variable, to implement pagination. Still not implementing LIMIT in to SQL itself, but this is very clean and understandable, at least from c#/vs.
Further examples of querying XML files. Very interesting stuff.
Did you like this post? Buy me a hot chocolate!
Posted in



