The problem
The default/sample code in the LinqScratchPad.aspx shows a TryYourOwnClass
class. Sadly, this class is not used in any way in the sample.
The sample code looks like this:
namespace Test {
class Program {
public static IEnumerable<SearchResultItem> Main(string str)
{
using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext())
{
return context.GetQueryable<SearchResultItem>().Take(10).ToList();
}
}
}
}
[PredefinedQuery("_templatename", ComparisonType.Contains, "sample")]
public class TryYourOwnClass
{
[IndexField("_name")]
public string Name {get; set;}
[IgnoreIndexFieldAttribute]
public string DoNotMapMe { get; set;}
}
As you can see, TryYourOwnClass
is defined, but is never used. I tried using TryYourOwnClass
as the type for GetQueryable
, but that won't run, as the Main
method returns an IEnumerable<SearchResultItem>
. And I cannot change the return type, because that will break the script as well.
The question
So how do I use custom classes in the LinqScratchPad to query an index?
Why am I trying to do that?
I'm working on a pretty constrained environment, where we are using a custom index with custom fields. Sadly, I cannot install any third-party tools like "Luke" or something like that. That's why I would like to use LinqScratchPad and a custom class to query the index using all the fields I want.