简体   繁体   English

db4o:如何在没有c#原始类的情况下从数据库检索对象?

[英]db4o: How to retrieve objects from DB without having the original class in c#?

I have db4o file created by some App (which I don't have source for) and I need to get all the data from this file. 我有一些应用程序创建的db4o文件(我没有源文件),我需要从该文件中获取所有数据。

In all examples I saw in tutorials there were Classes used for retrieving objects but what to do if I don't have these classes? 在教程中看到的所有示例中,都有用于检索对象的类,但是如果我没有这些类怎么办?

You can try it with LINQPad and my driver: http://www.gamlor.info/wordpress/2011/03/db4o-driver-for-linqpad/ 您可以使用LINQPad和我的驱动程序进行尝试: http ://www.gamlor.info/wordpress/2011/03/db4o-driver-for-linqpad/

Otherwise, you can explore the db4o reflection API: 否则,您可以探索db4o反射API:

Assuming you have no class, and just want to see everything. 假设您没有课程,只想看一切。 Something like this (don't remember the exact 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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM