简体   繁体   中英

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.

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/

Otherwise, you can explore the db4o reflection API:

Assuming you have no class, and just want to see everything. Something like this (don't remember the exact 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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