LibrarySites.Banner

Sitecore 7 LinqScratchPad

Sitecore 7 offers the possibility to take on a new paradigm shift from the way you typically build Sitecore sites. We think one of our MVP's put it best in saying

"It’s a bit like the revolutionary changes that Gmail brought to email – don’t organise, just search."

However, change is sometimes a little daunting. To help alleviate this we would like to introduce you to one of the tools that we will be providing to help you get up to speed really quickly. The LinqScratchPad is a tool that helps you prototype your code quickly and easily. There is no denying that JSFiddle.net is a fantastic tool to test things out to see your JavaScript working in front of your own eyes. With all the code samples and blog posts out on the net, we sometimes find ourselves questioning if the sample code will actually work or not. JavaScript has the added benefit of making it easy to run demonstrations in the browser so you can confirm that the code works or at least quickly see if it is not what you wanted.

The LinqScratchPad will allow you to run LINQ queries against your indexes all within the browser! Not only this but you can play around with different POCO's, settings and also test the performance of your queries.

Here is what it looks like:

Linq Scratch Pad

Now for a small peek into the future. In a soon to follow Update for Sitecore 7 we have added some more parts to the LinqScratchPad including

  • Ability to run externally hosted LINQ queries
  • Ability you to click on the code in our blogs and run the samples directly from the browser (just as long as you have an installed version of Sitecore 7)

For example, given the code below you could just use the text box and link below to launch it in your local environment.

using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext())
{
    return context.GetQueryable<SearchResultItem>().Take(10).ToList();
}

public class TryYourOwnClass 
{    
     [IndexField("_name")]
     public string Name {get; set;}    

     public string DoNotMapMe { get; set;}
}
Your local instance name: Launch Code

We have big plans for this tool and here are a couple of ideas we are playing with for future updates:

  • POCO Manager for storing references to prebuilt POCO's
  • C# CSS Styling
  • Run query X times to get average performance

If you have any ideas feel free to comment below.

Dev Team