Mehfuz's WebLog

Live crazy, think different!

Sponsors

News

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


Articles


Projects

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 www.codeplex.com/linqflickr and LinqExtender and TinyLinqToSql at www.codeplex.com/linqextender

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

http://weblogs.asp.net/scottgu/archive/2007/05/15/new-orcas-language-feature-anonymous-types.aspx

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

Enjoy!!

kick it on DotNetKicks.com

Comments

No Comments