代码之家  ›  专栏  ›  技术社区  ›  Peter Richter

RavenDB在什么条件下存储类实例的变量?

  •  0
  • Peter Richter  · 技术社区  · 9 年前

    我读到了 on this tutorial RavenDB可用于存储类的实例(例如 Menu 他们使用的对象)。我试着复制他们的例子,但使用了一个更简单的例子,用C#:

    using Raven.Client.Document;
    using Raven.Client;
    
    namespace Project3
    {
        class MainClass
        {
            public static void Main()
            {
                IDocumentStore docStore = new DocumentStore()
                {
                    Url = "http://localhost:8080",
                    DefaultDatabase = "Northwind"
                };
                docStore.Initialize();
                var session = docStore.OpenSession();
                StringHolder strHolder = new StringHolder();
                session.Store(strHolder);
                session.SaveChanges();
            }
        }
        class StringHolder
        {
            string name = "kj";
        }
    }
    

    然而,当我运行该程序并检查数据库时,我看到的日志如下:

    enter image description here

    所以 StringHolder 参数 name 未存储。为什么会出现这种情况?在教程中 菜单 Allergenics 导致类变量存储在结果文档中?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Thomas Freudenberg    9 年前

    财产 name 类的 StringHolder 是私有的,因此不会序列化。只有公共属性保存到数据库中。