Thursday, April 10, 2008

Standend query operators samples

Besides where, select, here are SelectMany, Selecting Indeces, Distinst...

SelectMany:

var authors = SampleData.Books.SelectMany(book => book.Authors);

equal expression:

var authors = from book in SampleData.Books
from author in book.Authors
select author.LastName

you can't write
var authors = from book in SampleData.Books SelectMany ........

select index:


var books = SampleData.Books
.Select((book, index) => new { index, book.Title })
.OrderBy(book => book.Title);
foreach (var bk in books)
{
Response.Write(bk.Title + bk.index);
}

No comments: