-->

关于使用db4o工作的几个问题(A few questions about working with

2019-09-01 02:01发布

I am trying the db4o object databse and so far I quite like what I am seeing, but I also read this post on stackoverflow db4o experiences? indicating that not everything that seems so easy is easy.

Right now, I have some questions regarding on how db4o is used in real world apps. So if you have any experience in working (especially in web app context) with db4o, I would love to hear them.

Here are my questions:

  1. How do you manage object identity when working with db4o stored objects?**
    Coming from RDBMS background where you normally always have a primary key / identity column for every table, I cant imagine right now on how to manage object identity in db4o.

    For example, if I was working with NHibernate / mysql and needed to find a User object by id, I would do session.Load(primaryKey) and it will be retrieved by its PK. It is also very common that the PK is defined as auto increment in the table definition.

  2. As there is no such option in db4o, my thought was using a Guid struct in order to identify some objects in the object database.

  3. Any tools to view the stored objects in the db?

    Is there something like SQL Server Management Studio (probably less sophisticated) in the db4o world? I would like to view the already stored data / objects in the db file.

  4. Are you screwed when renaming your domain objects?

    As far as I know when you rename a class, any previously stored instances in the db cannot be retrieved anymore. Is there a way to work around this issue? How do you deal with updates against a live database which already contains many objects?

  5. Can I exclude properties from being saved to the DB?

    If for example one domain object holds a reference to a (stateless) service object, then the service object will also be persisted if the domain object gets persisted, right?

It seems a bit odd to have a service instace saved in the database, at least to me.

Can you exclude the service instance from being saved? If the domain object is retrieved again, how can I make sure that the service is also injected in the instance again?

Answer 1:

1)使用db4o存储对象时如何管理对象的身份? db4o中你通常不会ID。 db4o的使用对象的身份来区分隔开的对象。 所以在内存中的同一个对象将是数据库的同一个对象。

只要一个你不序列化对象能正常工作。 但是只要对象序列化/断开。这不工作了。 例如,在网络的情形:您将数据发送到浏览器。 现在,你需要通过一些IDS稍后重新识别的对象。

我觉得这三个选项是可能的: -使用db4o的内部ID 。 然而此ID不是永远。 碎片整理数据库改变这个ID。 -使用db4o的UUID的 。 但是db4o的UUID的相当大 - 自己创建一个ID

2)有一个对象管理器工具来查看数据库。 然而,它极其在当前状态下的限制。 在我看来,这是db4o的一个巨大的缺点。

3)您可以创建别名,重命名类和领域等 。 然而改变继承层次结构不起作用。 然后,你需要将旧数据复制到新的实例。

4)是的。 您可以标记领域的瞬态与.NET的非序列化属性或自定义属性。



Answer 2:

在对象应该没有真正被使用定向数据库(如db4o的)对象的身份。 相反,一个用来查询和导航。 首先执行一个查询来获取一个/一些物体,然后使用导航,以获得他人。

“导航”手段,你只要按照字段的任何加载的对象/引用。

使用对象标识符可以被认为是不好的风格,大多数应用程序(我知道)根本就不使用它们。



Answer 3:

虽然这样做有DB4O一些工作,我写了一个简单的DB4O对象浏览器的工作原理不是包含在一个好得多。 给它一个尝试,它是开源的。

http://sourceforge.net/projects/db4oviewer/develop



文章来源: A few questions about working with db4o
标签: .net db4o