db40:如何从数据库中检索对象,而不需要c#中的原始类

本文关键字:不需要 原始 检索 db40 数据库 对象 | 更新日期: 2023-09-27 17:50:17

我有一些应用程序创建的db4o文件(我没有源),我需要从这个文件中获得所有的数据。

我在教程中看到的所有例子中都有用于检索对象的类,但如果我没有这些类该怎么办?

db40:如何从数据库中检索对象,而不需要c#中的原始类

您可以尝试使用LINQPad和我的驱动程序:http://www.gamlor.info/wordpress/2011/03/db4o-driver-for-linqpad/

否则,您可以探索db40反射API:

假设你没有课,只是想看看所有的东西。像这样(不记得确切的API了):

IQuery query = container.Query();
IEnumerable allObjects = query.Execute();
foreach(Object item : allObjects){
    GenericObject dbObject = (GenericObject)item; // Note: If db4o finds actuall class, it will be the right class, otherwise GenericObject. You may need to do some checks and casts
    dbObject.GetGenericClass().GetDeclaredFields(); // Find out fields
    object fieldData = dbObject.Get(0); // Get the field at index 0. The GetDeclaredFields() tells you which field is at which index
}