CSharpFeeds - All your C# feeds in one place.

Sponsors

Saturday, August 22, 2009

BLinq - Linq to Bing Search APIs

by via Nikhil Kothari's Weblog on 8/22/2009 5:35:45 PM

As part of validating and playing with some of the extensibility features in .NET RIA Services, I needed to write a LINQ provider. This was also a good opportunity to delve into some of the deeper technical aspects of the IQueryable construct, expression trees and related concepts, which I had not gotten into first-hand until now. For my prototyping, I decided to write a LINQ provider for querying Bing to search for pages and images. This post will focus on using the LINQ provider itself, and seeing it in action, and in my next post I'll tie it all back to .NET RIA Services. I am calling this BLinq. :-)

Bing has a new search API that provides you the option of using REST interface (XML or JSON) or a SOAP interface. My LINQ provider provides a more natural LINQ syntax that you can now use without having to worry about protocol details, web requests, URIs etc. Under the covers the LINQ functionality builds on the REST/XML API.

Here is an example of a basic search for pages using BLinq:

BingContext bing = new BingContext(appKey);
IQueryable<PageSearchResult> pagesQuery =
    from p in bing.Pages
    where p.Query == "nikhil"
    select p;

foreach (PageSearchResult page in pagesQuery) {
    // Write out page members (title, uri, description, display URL and date)
}

Simple enough? BingContext is very much like a Linq-to-SQL DataContext. It has a Pages property of type IQueryable<PageSearchResult> (ala a Table<T> in a DataContext). Of course this is LINQ, and so you can use standard LINQ constructs like Skip and Take for example to page over the search results. For example:


[Full post continued here...]
email it!bookmark it!digg it!

Original Post: BLinq - Linq to Bing Search APIs

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us