我需要在我的项目中使用嵌入式RavenDb。我安装了Nuget包“RavenDb.Embedded”。之后,项目中添加了以下dll:
我的实体类用于存储数据:
public class TagLastRead
{
public string Id { get; set; }
public DateTime LastReceiveDateTime { get; set; }
}
我创建了一个RavenConfig类,如下所示:
public class RavenConfig
{
private static IDocumentStore _store;
public static IDocumentStore Store
{
get
{
if (_store == null)
throw new InvalidOperationException(
"IDocumentStore has not been initialized.");
return _store;
}
}
public static IDocumentStore Initialize()
{
_store = new EmbeddableDocumentStore
{
ConnectionStringName = "LocalTagReads"
};
_store.Conventions.IdentityPartsSeparator = "-";
_store.Initialize();
IndexCreation.CreateIndexes(Assembly.GetCallingAssembly(), Store);
return _store;
}
}
我的app.Config文件在“connectionStrings”下面有以下行
<add name="LocalTagReads" connectionString="DataDir = ~\Data" />
我需要访问RavenDb的类看起来像这样
public class SampleClass
{
public SampleClass()
{
RavenConfig.Initialize();
}
public DoStuff(TagInfo value)
{
using(IDocumentSession session = RavenConfig.Store.OpenSession())
{
TagLastRead t = session.Load<TagLastRead>(value.Tagname);
if (t == null)
{
t = new TagLastRead();
session.Store(t,value.Tagname);
}
t.LastReceiveDateTime = value.Time;
session.SaveChanges();
}
}
}
创建“Data”目录,其中包含一些文件和子目录。问题是当遇到以下代码行时
TagLastRead t = session.Load<TagLastRead>(value.Tagname);
程序永远挂起,输出中没有任何错误。 通过在调试中点击暂停按钮,我可以看到它停留在MemoryStatistics类中。
修改
我使用的是3.0.30037版本
调用IndexCreation.CreateIndexes
或session.Load
或session.SaveChanges
时,输出日志中出现以下异常
等待一段时间后,我有以下错误
System.InvalidOperationException:查询失败。请参阅内部异常了解详细信---&GT; System.TimeoutException:操作超时后:00:01:41.1979667 ---&gt; System.AggregateException:AsyncHelpers.Run方法引发异常。 ---&GT; System.Threading.Tasks.TaskCanceledException:任务已取消。 在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() 在Raven.Client.Connection.Implementation.HttpJsonRequest。&lt;&gt; c__DisplayClasse。&lt; b__d&gt; d__10.MoveNext()在c:\ Builds \ RavenDB-Stable-3.0 \ Raven.Client.Lightweight \ Connection \ Implementation \ HttpJsonRequest。 cs:第226行