I am able to create and run this index just fine in Raven Studio / Indexes:
------------------------------------------------------------------
Index: UpdateMessagesCountByTypeWeek
from msg in docs.UpdateMessages
where msg.msgtype != "perf"
let c = System.Threading.Thread.CurrentThread.CurrentCulture
let w = c.Calendar.GetWeekOfYear(msg.timestamp, c.DateTimeFormat.CalendarWeekRule, c.DateTimeFormat.FirstDayOfWeek)
select new
{
week = w,
type = msg.msgtype,
count = 1
}
from result in results
group result by new {
result.week,
result.type,
}
into g
select new
{
g.Key.week,
g.Key.type,
count = g.Sum(x => x.count)
}
------------------------------------------------------------------
But when I do the following in code:
------------------------------------------------------------------
public class UpdateMessagesCountByTypeWeek : AbstractIndexCreationTask<UpdateMessage, UpdateMessageCountByTypeWeek>
{
public UpdateMessagesCountByTypeWeek()
{
Map = msgs => from msg in msgs
where msg.msgtype != "perf"
let c = System.Threading.Thread.CurrentThread.CurrentCulture
let w = c.Calendar.GetWeekOfYear(msg.timestamp, c.DateTimeFormat.CalendarWeekRule, c.DateTimeFormat.FirstDayOfWeek)
select new
{
week = w,
type = msg.msgtype,
count = 1
};
Reduce = results => from result in results
group result by new {
result.week,
result.type,
}
into g
select new
{
g.Key.week,
g.Key.type,
count = g.Sum(x => x.count)
};
}
}
------------------------------------------------------------------
I get this error:
------------------------------------------------------------------
e:\_IntelProjects\UT\UtRepository\Data\Test\Tenants\IndexTests\IndexDefinitions\TemporaryIndexDefinitionsAsSource\ikqs2ytf.0.cs(28,359) : error CS0103: The name 'Thread' does not exist in the current context
at Raven.Database.Linq.QueryParsingUtils.Compile(String source, String name, String queryText, OrderedPartCollection`1 extensions, String basePath) in c:\Builds\RavenDB-Stable\Raven.Database\Linq\QueryParsingUtils.cs:line 273
------------------------------------------------------------------
Off the top of my head this seems like something I ought to be able to do...thanks.