TerraServer Sample: A LINQ Provider

Over the holidays Alex Turner, Mary Deyo and I added a new sample to the downloadable version of the CSharp samples that accompany Visual Studio 2008. This sample is called the LinqToTerraServerProvider, and it appears in a sub-directory called WebServiceLinqProvider. The LINQ provider technology that makes this sample possible is also used by other tools such as LINQ to Amazon, LINQ to LDAP, LINQ to SharePoint, and LINQ to Google Desktop.

When you download the samples, unzip the package into your Documents or My Documents directory or some other location where you have full rights. Navigate to the LinqSamples directory and then the directory called WebServiceLinqProvider. Open the LinqToTerraServerProvider solution. If you get a warning stating the "Project location is not trusted" you can safely ignore it. To avoid getting the warning in the future, right click on the solution file and choose properties. Select the Unblock button in the security section.

TerraServer

The TerraServer example shows how to create a LINQ provider. The provider technology makes it possible for your to extend LINQ to enable querying a new data source. For instance, LINQ ships with the ability to query SQL servers, XML files and generic objects. The LINQ provider technology allows you to extend LINQ so you can query a new data source such as a text file or a web site. This particular sample shows how to write a provider that makes it possible for LINQ developers to query the web service provided by the TerraServer mapping and aerial photography web site.

The following query from the sample will return a list of states in the US that have a city, town or some other location called Redmond:

 var query1 = from place in terraPlaces
             where place.Name== "Redmond"
             select place.State;

Here is the data returned by this query:

 Washington
Colorado
Oregon
Utah
West Virginia
Pennsylvania

The query shown below requests a list of the places, ordered by state, that have a place called either Johannesburg, Yachats, or Seattle:

 string[] places = { "Johannesburg", "Yachats", "Seattle" };

var query3 = from place in terraPlaces
             where places.Contains(place.Name)
             orderby place.State
             select new { place.Name, place.State };
 Here are the results:

 { Name = Johannesburg, State = California }
{ Name = Johannesburg, State = Michigan }
{ Name = Yachats, State = Oregon }
{ Name = Seattle, State = Washington }
{ Name = Johannesburg, State = Wisconsin }

Genevieve Orchard was the primary creator of these samples. She works on the docs team, and also wrote a wonderful walk through that can help you understand this sample.

Genevieve's walk through: https://msdn2.microsoft.com/en-us/library/bb546158.aspx

People interested in this topic might also want to read Matt Warren's in depth study of LINQ providers. Some of the code that Matt shows in his series of posts was included in Genevieve's sample.

 

kick it on DotNetKicks.com

Comments

  • Anonymous
    January 06, 2008
    You've been kicked (a good thing) - Trackback from DotNetKicks.com

  • Anonymous
    January 06, 2008
    Nice!! More, Linq.Flickr(www.codeplex.com/linqflickr) and LinqExtender(www.codeplex.com/linqextender) :-) LinqExtender is used to wrap all these things , so that making terraservice,on it will require no queryable knowledge at all. Pleasssssssssse. check it out...

  • Anonymous
    January 07, 2008
    LINQ (language integrated query) is one of the new features provided with VS 2008 and .NET 3.5. 

  • Anonymous
    January 07, 2008
    LINQ (language integrated query) is one of the new features provided with VS 2008 and .NET 3.5. 

  • Anonymous
    January 09, 2008
    LINQ (language integrated query) is one of the new features provided with VS 2008 and .NET 3.5. 

  • Anonymous
    January 10, 2008
    【原文地址】DynamicLINQ(Part1:UsingtheLINQDynamicQueryLibrary) 【原文发表日期】Monday,January07,200...

  • Anonymous
    January 18, 2008
    【原文地址】 Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library) 【原文发表日期】 Monday, January 07, 2008

  • Anonymous
    January 28, 2008
    Ran across this post on Charlie Calvert's Community Blog using TerraServer's Web Services with LINQ...why

  • Anonymous
    January 28, 2008
    Ran across this post on Charlie Calvert's Community Blog using TerraServer's Web Services with LINQ...why

  • Anonymous
    February 17, 2008
    The comment has been removed

  • Anonymous
    February 17, 2008
    The comment has been removed

  • Anonymous
    February 17, 2008
    【原文地址】 Feb 17th Links: ASP.NET, ASP.NET AJAX, Visual Studio, .NET 【原文发表日期】 Sunday, February 17, 2008

  • Anonymous
    May 06, 2008
    http://news.justia.com/cases/featured/north-carolina/ncedce/4:2008cv00067/93724/

  • Anonymous
    May 20, 2008
    Work at home moms. Work from home moms. Wahm com the online magazine for work at home moms. Moms work from home. Moms work at home.

  • Anonymous
    March 03, 2009
    动态LINQ(第一部分:使用LINQ动态查询库) 【原文地址】DynamicLINQ(Part1:UsingtheLINQDynamicQueryLibrary) 【原文发...

  • Anonymous
    May 30, 2009
    <a href= http://tabletest.livejournal.com/ >bodrya4kom!!!</a>   <a href= http://tabletest.xanga.com/ >bodrya4kom!!!</a>   <a href= http://tabletest.wordpress.com/ >bodrya4kom!!!</a>   <a href= http://tabletestx.blogspot.com/ >bodrya4kom!!!</a>