Mehfuz's WebLog

Live crazy, think different!



Passionate about cutting edge technologies and facinated by the modern web and phone revolution.Currently working at Telerik Corporation, the leading .net component vendor.
Follow me



Anonymous Type in LinqExtender

It is now possible for LinqExtender implemented providers to have anonymous type in the select query.

For example, consider the following

SqlContext<Book> context = new SqlContext<Book>();

var query = (from q in context
            orderby q.LastUpdated descending
            select new { q.ISBN, q.Title}).Take(1);

var book = query.single();

// do something useful

Console.WriteLine (book.ISBN   + "  " + book.Title);

This sample done using TinyLinqToSql custom provider made on LinqExtender. Here I have some books in database and i want the top 1 , latest book out of it, also I need only two items, ISBN and Title, which I just need to show to in my current scope, without declaring any formal type, in this case the anonymous type can be useful and can be done in the above way.

By the time , I am writing this post , I was having some problem with codeplex , for uploading the latest code of LinqExtender. Hope , it will be done , when you are reading this post.

Also, I have uploaded a new version Linq.Flickr , with latest LinqExtender, so you can have the taste of anonymous type in there as well. Though this is out of scope of the post, but need to say that, now you can get photos with order by Date_Posted/ Date_Taken  asc/dsc respectively. Flickr API also supports, other two properties Relevance and Interestingness, but these two only support sort by ascending , therefore , I omitted this half feature, hope they will come with both way order for these two parameters.

No need to say, you can download Linq.Flickr at and LinqExtender and TinyLinqToSql at

Also, I found this cool post of Scott Gutherie for anonymous type, you might need to look at it as well.

Finally, an anon but cool guy from community named Reski Mills helped me implement this anon type real fast, thanks man!


kick it on


No Comments