在RavenDB上安装索引期间,当前上下文错误中不存在名称“NodaTimeField”

时间:2016-01-26 10:29:41

标签: ravendb nodatime

我在RavenDB索引中使用NodaTime的LocalDate。 以下是索引的示例:

public class TaskIndex : AbstractIndexCreationTask<ScheduleTask>
{
    public TaskIndex()
    {
        Map = tasks => from task in tasks
            select new
            {
                task.Name,
                PlannedStartDate = task.PlannedStartDate.AsLocalDate().Resolve(),
                PlannedDueDate = task.PlannedDueDate.AsLocalDate().Resolve()
            };

        Index(x => x.Name, FieldIndexing.Analyzed);
        Store(x => x.Name, FieldStorage.Yes);
        TermVector(x => x.Name, FieldTermVector.WithPositionsAndOffsets);
    }
}

我按照here所述安装了RavenDB-NodaTime软件包。

这是我用来安装索引的一段代码:

var assembly = AppDomain.CurrentDomain.Load(new AssemblyName
{
    Name = "cs.Scheduling"
});
var catalog = new AssemblyCatalog(assembly);
var provider = new CompositionContainer(catalog);
var commands = documentStore.DatabaseCommands.ForDatabase(dbName);
IndexCreation.CreateIndexes(provider, commands, documentStore.Conventions);

documentStore配置了默认数据库,但后来我使用它来安装索引到dbName的不同(租户)数据库名称。

在安装索引期间,我遇到了一个例外:The name 'NodaTimeField' does not exist in the current context

我有一个默认数据库,它与我尝试安装索引的数据库完全不同。所以基本上情况类似于here所描述的情况,但我使用的是独立版本的RavenDB服务器。

我试图找出我在那里的建议,但却无法做到:

embeddableDocumentStore.ServerIfEmbedded.Options.DatabaseLandlord.SetupTenantConfiguration += configuration =>
            {
                configuration.Catalog.Catalogs.Add(new TypeCatalog(typeof(DeleteOnConflict)));
                configuration.Catalog.Catalogs.Add(new TypeCatalog(typeof(PutOnConflict)));
            };

我使用的RavenDB版本是2.5.2956 RavenDB.Client.NodaTime - 2.5.10。

希望得到你的帮助。感谢。

2 个答案:

答案 0 :(得分:1)

在我的情况下,这是一个非常愚蠢的错误。我不久前在安装RavenDB服务器时将其安装到非默认目标。后来一些RavenDB更新被安装到默认目的地(即\Program Files (x86)\RavenDB)。当我安装RavenDB-NodaTime软件包时,我把它放到了错误的目的地(\Program Files (x86)\RavenDB)。

在检测到此问题并正确配置RavenDB服务器后,标题中描述的错误已经消失。

希望这个答案可以帮助别人。

PS 后来在从db读取数据时出现了反序列化错误(RavenDB不知道如何将"yyyy-MM-dd"格式的字符串中的日期反序列化为LocalDate对象)我通过在Steven answer建议的store.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);来电store.Initialize();后致电{{1}}来解决问题。

答案 1 :(得分:0)

我认为答案是您的租户数据库没有捆绑&#34;已激活&#34;您的数据库文档(在Raven 3中的设置下)应该具有类似

的内容
"Raven/ActiveBundles": "Encryption;Compression;NodaTime"

你也必须致电

store.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);

我在store.Initialize()之后调用它。完成这两项操作后,您可能需要通过重新保存文档来修复现有数据(不确定是否有其他方法)。新数据将被正确存储,如2016-2-3&#39;应该使您的索引返回数据的格式。