RavenDB 错误:var 存储不是全局变量。如何创建一个可以使用访问文档存储的类?非常感谢任何有关此代码拒绝运行原因的评论
class Program
{
static void Main(string[] args)
{
var store = new DocumentStore
{
Urls = new[] { "http://localhost:8080" },
Database = "Tasks"
};
store.Initialize();
}
class OtherProgram
using (var session = Store.OpenSession())
{
var task = session.Load<Entity>(combinedInitial + email)
//More code
}
最佳答案
通常,您会为每个应用程序使用一个文档存储实例(单例)。
在此处查看初始化 DocumentnStore 的常见模式:
https://ravendb.net/learn/inside-ravendb-book/reader/4.0/2-zero-to-ravendb#the-document-store
查看此演示中的演练和说明:
https://demo.ravendb.net/demos/csharp/basics/the-document-store
也可以按照Bootcamp存储库中的示例进行操作
https://github.com/ravendb/bootcamp/tree/v5.x/src/unit1/lesson4#exercise-moving-the-documentstore-instance-to-a-singleton-class
关于c# - RavenDB 错误 : I can't access var store from a different class. 任何建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70634611/