Project Description
LINQ to Wikipedia is a custom LINQ query provider implementation for the Mediawiki API that translates LINQ queries into HTTP requests to access Wikipedia information. LINQ stands for Language Integrated Query and is one of the core features of Microsoft's .NET Framework 3.5 release. More information can be found via the MSDN website on
http://msdn.microsoft.com.
Be sure to visit my
Blog for more information including an explanation of the
LinqToWikipedia provider as well as a tutorial on creating your own Linq provider.
Features
- Custom query provider that translates LINQ queries into HTTP requests that interact with the Wikipedia API.
- Supports two query types:
- OpenSearch - Support for the OpenSearch protocol
- Keyword Query - Allows for querying Wikipedia using multiple keywords
- LinqToWikipedia Blog with documentation and tutorial
- Support for proxy configuration for use behind a firewall
- Live Demo site
- Ships with full Visual Studio 2008 solution with source code and samples (demo sites above included)
Code example
Open Search:
WikipediaContext datacontext = new WikipediaContext();
//WikipediaContext datacontext = new WikipediaContext(new WebProxy("yourproxyserver", 80), new NetworkCredential("username", "password", "domain"));
var opensearch = (
from wikipedia in datacontext.OpenSearch
where wikipedia.Keyword == "linq"
select wikipedia).Take(10);
// dl_results is an ASP.NET DataList
dl_results.DataSource = opensearch;
dl_results.DataBind();
Keyword Query:
WikipediaContext datacontext = new WikipediaContext();
//WikipediaContext datacontext = new WikipediaContext(new WebProxy("yourproxyserver", 80), new NetworkCredential("username", "password", "domain"));
var query = (
from wikipedia in datacontext.KeywordSearch
where
wikipedia.Keyword == "linq" &&
wikipedia.Keyword == "wikipedia" &&
wikipedia.Keyword == "code" &&
wikipedia.Keyword == ".net"
select wikipedia).Skip(3).Take(25);
// dl_results is an ASP.NET DataList
dl_results.DataSource = query;
dl_results.DataBind();
Status
- 2/16/2009 - Added "UserAgent" to HTTP headers to fix "forbidden access" errors to "HttpRequest.cs" file - see source code
- 1/11/2009 - Built the first stable release of the LinqToWikipedia provider / ver. 1.0.0.0
- 1/9/2010 - Uploaded initial development build to TFS
Disclaimer
- This project is meant as a basic sample on implementing custom LINQ query providers. It hasn't been tested thoroughly and I do not provide any support whatsoever. Do not use it in a production environment without proper testing and validation of the technology's behavior. Users are most welcome to report issues and bugs through the Issue Tracker on this site.